From 91121e8c32aa18028477b14c34d1ea8535185e11 Mon Sep 17 00:00:00 2001 From: Danny Graham Date: Wed, 3 Jul 2013 08:38:47 -0700 Subject: [PATCH] updates tests and documentation with category support --- lib/rss.js | 6 +++--- readme.md | 6 ++++-- test/test.js | 20 ++++++++++++++++++-- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/lib/rss.js b/lib/rss.js index 3732952..7e132bc 100644 --- a/lib/rss.js +++ b/lib/rss.js @@ -70,9 +70,9 @@ function generateXML (data){ ifTruePush(item.url, item_values, { link: item.url }); ifTruePush(item.link || item.guid || item.title, item_values, { guid: [ { _attr: { isPermaLink: !item.guid && !!item.url } }, item.guid || item.url || item.title ] }); - for (var i in item.categories) { - ifTruePush(item.categories[i], item_values, { category: { _cdata: item.categories[i] } }); - } + item.categories.forEach(function(category) { + ifTruePush(category, item_values, { category: { _cdata: category } }); + }); ifTruePush(item.author || data.author, item_values, { 'dc:creator': { _cdata: item.author || data.author } }); ifTruePush(item.date, item_values, { pubDate: new Date(item.date).toGMTString() }); diff --git a/readme.md b/readme.md index 575450e..e7c158c 100644 --- a/readme.md +++ b/readme.md @@ -33,6 +33,7 @@ description: 'use this for the content. It can include html.', url: 'http://example.com/article4?this&that', // link to the item guid: '1123', // optional - defaults to url + categories: ['Category 1','Category 2','Category 3','Category 4'], // optional - array of item categories author: 'Guest Author', // optional - defaults to feed author property date: 'May 27, 2012' // any format that js Date can parse. }); @@ -61,11 +62,12 @@ an have any number of items. Ten to tenty is usually good. * _guid_ A unique string feed readers use to know if an item is new or has already been seen. If you use a guid never change it. If you don't provide a guid then your item urls must be unique. + * _categories_ Optional. If provided, each array item will be added as a category element * _author_ Optional. If included it is the name of the item's creator. If not provided the item author will be the same as the feed author. This is typical except on multi-author blogs. - * _date_ The date and time of when the intem was created. Feed - readers use this to determin the sort order. Some readers will also use it to determin + * _date_ The date and time of when the item was created. Feed + readers use this to determine the sort order. Some readers will also use it to determine if the content should be presented as unread. ### Methods diff --git a/test/test.js b/test/test.js index 597c5c4..5faa7fd 100644 --- a/test/test.js +++ b/test/test.js @@ -50,9 +50,17 @@ module.exports = { url: 'http://example.com/article4?this&that', author: 'Guest Author', date: 'May 27, 2012 04:00:00 GMT' + }) + .item({ + title: 'item 5 & test for categories', + description: 'description 5', + url: 'http://example.com/article5', + categories: ['Category 1','Category 2','Category 3','Category 4'], + author: 'Guest Author', + date: 'May 28, 2012 04:00:00 GMT' }); - var expectedResult = '\n<![CDATA[title]]>http://example.comhttp://example.com/icon.pngtitlehttp://example.comNodeJS RSS Module' + new Date().toUTCString() +'<![CDATA[item 1]]>http://example.com/article1http://example.com/article1Thu, 24 May 2012 04:00:00 GMT<![CDATA[item 2]]>http://example.com/article2http://example.com/article2Fri, 25 May 2012 04:00:00 GMT<![CDATA[item 3]]>http://example.com/article3item3Sat, 26 May 2012 04:00:00 GMT<![CDATA[item 4 & html test with <strong>]]>html]]>http://example.com/article4?this&thathttp://example.com/article4?this&thatSun, 27 May 2012 04:00:00 GMT'; + var expectedResult = '\n<![CDATA[title]]>http://example.comhttp://example.com/icon.pngtitlehttp://example.comNodeJS RSS Module' + new Date().toUTCString() +'<![CDATA[item 1]]>http://example.com/article1http://example.com/article1Thu, 24 May 2012 04:00:00 GMT<![CDATA[item 2]]>http://example.com/article2http://example.com/article2Fri, 25 May 2012 04:00:00 GMT<![CDATA[item 3]]>http://example.com/article3item3Sat, 26 May 2012 04:00:00 GMT<![CDATA[item 4 & html test with <strong>]]>html]]>http://example.com/article4?this&thathttp://example.com/article4?this&thatSun, 27 May 2012 04:00:00 GMT<![CDATA[item 5 & test for categories]]>http://example.com/article5http://example.com/article5Mon, 28 May 2012 04:00:00 GMT'; var result = feed.xml(); test.equal(result.length, expectedResult.length); @@ -94,9 +102,17 @@ module.exports = { url: 'http://example.com/article4?this&that', author: 'Guest Author', date: 'May 27, 2012 04:00:00 GMT' + }) + .item({ + title: 'item 5 & test for categories', + description: 'description 5', + url: 'http://example.com/article5', + categories: ['Category 1','Category 2','Category 3','Category 4'], + author: 'Guest Author', + date: 'May 28, 2012 04:00:00 GMT' }); - var expectedResult = '\n<![CDATA[title]]>http://example.comNodeJS RSS Module' + new Date().toUTCString() +'<![CDATA[item 1]]>http://example.com/article1http://example.com/article1Thu, 24 May 2012 04:00:00 GMT<![CDATA[item 2]]>http://example.com/article2http://example.com/article2Fri, 25 May 2012 04:00:00 GMT<![CDATA[item 3]]>http://example.com/article3item3Sat, 26 May 2012 04:00:00 GMT<![CDATA[item 4 & html test with <strong>]]>html]]>http://example.com/article4?this&thathttp://example.com/article4?this&thatSun, 27 May 2012 04:00:00 GMT'; + var expectedResult = '\n<![CDATA[title]]>http://example.comNodeJS RSS Module' + new Date().toUTCString() +'<![CDATA[item 1]]>http://example.com/article1http://example.com/article1Thu, 24 May 2012 04:00:00 GMT<![CDATA[item 2]]>http://example.com/article2http://example.com/article2Fri, 25 May 2012 04:00:00 GMT<![CDATA[item 3]]>http://example.com/article3item3Sat, 26 May 2012 04:00:00 GMT<![CDATA[item 4 & html test with <strong>]]>html]]>http://example.com/article4?this&thathttp://example.com/article4?this&thatSun, 27 May 2012 04:00:00 GMT<![CDATA[item 5 & test for categories]]>http://example.com/article5http://example.com/article5Mon, 28 May 2012 04:00:00 GMT'; var result = feed.xml(); test.equal(result.length, expectedResult.length);