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