Splits up type js into js and json.

This commit is contained in:
Lars Jung 2012-10-11 18:28:12 +02:00
parent 69ffcc2d32
commit a8e0c049f2
5 changed files with 12 additions and 28 deletions

View file

@ -1,29 +1,7 @@
modulejs.define('parser/generic-json', ['_', '$', 'core/settings', 'model/entry'], function (_, $, settings, Entry) {
modulejs.define('parser/generic-json', ['_', '$', 'model/entry'], function (_, $, Entry) {
var parseJson = function (absHref, json) {
if (!settings.custom) {
settings.custom = {};
}
if (_.has(json, 'customHeader')) {
settings.custom.header = json.customHeader;
}
if (_.has(json, 'customFooter')) {
settings.custom.footer = json.customFooter;
}
return _.map(json.entries, function (jsonEntry) {
return Entry.get(jsonEntry.absHref, jsonEntry.time, jsonEntry.size, jsonEntry.status, jsonEntry.content);
});
},
parseJsonStr = function (absHref, jsonStr) {
return parseJson(absHref, JSON.parse($.trim(jsonStr) || '{}'));
},
parse = function (absHref, html) {
var parse = function (absHref, html) {
var id = '#data-generic-json',
$html = $(html),
@ -33,7 +11,11 @@ modulejs.define('parser/generic-json', ['_', '$', 'core/settings', 'model/entry'
$id = $html.find(id);
}
return parseJsonStr(absHref, $id.text());
var json = JSON.parse($.trim($id.text()) || '{}');
return _.map(json.entries, function (jsonEntry) {
return Entry.get(jsonEntry.absHref, jsonEntry.time, jsonEntry.size, jsonEntry.status, jsonEntry.content);
});
};
return {