added functionality to add custom elements

This commit is contained in:
Max Nowack
2014-11-11 13:49:37 +01:00
parent 491340b91e
commit 040d854c57

View File

@@ -10,6 +10,14 @@ function ifTruePush(bool, array, data) {
} }
} }
function ifTruePushArray(bool, array, dataArray) {
if(!bool) return;
dataArray.forEach(function(item) {
ifTruePush(item, array, item);
});
}
function generateXML (data){ function generateXML (data){
var channel = []; var channel = [];
@@ -40,6 +48,8 @@ function generateXML (data){
}); });
} }
ifTruePushArray(data.custom, channel, data.custom);
data.items.forEach(function(item) { data.items.forEach(function(item) {
var item_values = [ var item_values = [
{ title: { _cdata: item.title } } { title: { _cdata: item.title } }
@@ -84,6 +94,8 @@ function generateXML (data){
} }
} }
ifTruePushArray(item.custom, item_values, item.custom);
channel.push({ item: item_values }); channel.push({ item: item_values });
}); });
@@ -130,6 +142,7 @@ function RSS (options, items) {
this.ttl = options.ttl; this.ttl = options.ttl;
//option to return feed as GeoRSS is set automatically if feed.lat/long is used //option to return feed as GeoRSS is set automatically if feed.lat/long is used
this.geoRSS = options.geoRSS || false; this.geoRSS = options.geoRSS || false;
this.custom = options.custom || [];
this.items = items || []; this.items = items || [];
this.item = function (options) { this.item = function (options) {
@@ -144,7 +157,8 @@ function RSS (options, items) {
date: options.date, date: options.date,
lat: options.lat, lat: options.lat,
long: options.long, long: options.long,
enclosure: options.enclosure || false enclosure: options.enclosure || false,
custom: options.custom || []
}; };
this.items.push(item); this.items.push(item);