mirror of
https://github.com/LightAir/turbo-rss.git
synced 2026-02-04 03:56:19 +00:00
updates tests and documentation with category support
This commit is contained in:
@@ -70,9 +70,9 @@ function generateXML (data){
|
|||||||
ifTruePush(item.url, item_values, { link: item.url });
|
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 ] });
|
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) {
|
item.categories.forEach(function(category) {
|
||||||
ifTruePush(item.categories[i], item_values, { category: { _cdata: item.categories[i] } });
|
ifTruePush(category, item_values, { category: { _cdata: category } });
|
||||||
}
|
});
|
||||||
|
|
||||||
ifTruePush(item.author || data.author, item_values, { 'dc:creator': { _cdata: item.author || data.author } });
|
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() });
|
ifTruePush(item.date, item_values, { pubDate: new Date(item.date).toGMTString() });
|
||||||
|
|||||||
@@ -33,6 +33,7 @@
|
|||||||
description: 'use this for the content. It can include html.',
|
description: 'use this for the content. It can include html.',
|
||||||
url: 'http://example.com/article4?this&that', // link to the item
|
url: 'http://example.com/article4?this&that', // link to the item
|
||||||
guid: '1123', // optional - defaults to url
|
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
|
author: 'Guest Author', // optional - defaults to feed author property
|
||||||
date: 'May 27, 2012' // any format that js Date can parse.
|
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_ <unique string> A unique string feed readers use to know if an item is new or has already been seen.
|
* _guid_ <unique string> 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
|
If you use a guid never change it. If you don't provide a guid then your item urls must
|
||||||
be unique.
|
be unique.
|
||||||
|
* _categories_ <array> Optional. If provided, each array item will be added as a category element
|
||||||
* _author_ <string> Optional. If included it is the name of the item's creator.
|
* _author_ <string> 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
|
If not provided the item author will be the same as the feed author. This is typical
|
||||||
except on multi-author blogs.
|
except on multi-author blogs.
|
||||||
* _date_ <Date object or date string> The date and time of when the intem was created. Feed
|
* _date_ <Date object or date string> The date and time of when the item was created. Feed
|
||||||
readers use this to determin the sort order. Some readers will also use it to determin
|
readers use this to determine the sort order. Some readers will also use it to determine
|
||||||
if the content should be presented as unread.
|
if the content should be presented as unread.
|
||||||
|
|
||||||
### Methods
|
### Methods
|
||||||
|
|||||||
20
test/test.js
20
test/test.js
@@ -50,9 +50,17 @@ module.exports = {
|
|||||||
url: 'http://example.com/article4?this&that',
|
url: 'http://example.com/article4?this&that',
|
||||||
author: 'Guest Author',
|
author: 'Guest Author',
|
||||||
date: 'May 27, 2012 04:00:00 GMT'
|
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 = '<?xml version="1.0" encoding="UTF-8"?>\n<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[title]]></title><description><![CDATA[description]]></description><link>http://example.com</link><image><url>http://example.com/icon.png</url><title>title</title><link>http://example.com</link></image><generator>NodeJS RSS Module</generator><lastBuildDate>' + new Date().toUTCString() +'</lastBuildDate><atom:link href="http://example.com/rss.xml" rel="self" type="application/rss+xml"/><item><title><![CDATA[item 1]]></title><description><![CDATA[description 1]]></description><link>http://example.com/article1</link><guid isPermaLink="true">http://example.com/article1</guid><dc:creator><![CDATA[Dylan Greene]]></dc:creator><pubDate>Thu, 24 May 2012 04:00:00 GMT</pubDate></item><item><title><![CDATA[item 2]]></title><description><![CDATA[description 2]]></description><link>http://example.com/article2</link><guid isPermaLink="true">http://example.com/article2</guid><dc:creator><![CDATA[Dylan Greene]]></dc:creator><pubDate>Fri, 25 May 2012 04:00:00 GMT</pubDate></item><item><title><![CDATA[item 3]]></title><description><![CDATA[description 3]]></description><link>http://example.com/article3</link><guid isPermaLink="false">item3</guid><dc:creator><![CDATA[Dylan Greene]]></dc:creator><pubDate>Sat, 26 May 2012 04:00:00 GMT</pubDate></item><item><title><![CDATA[item 4 & html test with <strong>]]></title><description><![CDATA[description 4 uses some <strong>html</strong>]]></description><link>http://example.com/article4?this&that</link><guid isPermaLink="true">http://example.com/article4?this&that</guid><dc:creator><![CDATA[Guest Author]]></dc:creator><pubDate>Sun, 27 May 2012 04:00:00 GMT</pubDate></item></channel></rss>';
|
var expectedResult = '<?xml version="1.0" encoding="UTF-8"?>\n<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[title]]></title><description><![CDATA[description]]></description><link>http://example.com</link><image><url>http://example.com/icon.png</url><title>title</title><link>http://example.com</link></image><generator>NodeJS RSS Module</generator><lastBuildDate>' + new Date().toUTCString() +'</lastBuildDate><atom:link href="http://example.com/rss.xml" rel="self" type="application/rss+xml"/><item><title><![CDATA[item 1]]></title><description><![CDATA[description 1]]></description><link>http://example.com/article1</link><guid isPermaLink="true">http://example.com/article1</guid><dc:creator><![CDATA[Dylan Greene]]></dc:creator><pubDate>Thu, 24 May 2012 04:00:00 GMT</pubDate></item><item><title><![CDATA[item 2]]></title><description><![CDATA[description 2]]></description><link>http://example.com/article2</link><guid isPermaLink="true">http://example.com/article2</guid><dc:creator><![CDATA[Dylan Greene]]></dc:creator><pubDate>Fri, 25 May 2012 04:00:00 GMT</pubDate></item><item><title><![CDATA[item 3]]></title><description><![CDATA[description 3]]></description><link>http://example.com/article3</link><guid isPermaLink="false">item3</guid><dc:creator><![CDATA[Dylan Greene]]></dc:creator><pubDate>Sat, 26 May 2012 04:00:00 GMT</pubDate></item><item><title><![CDATA[item 4 & html test with <strong>]]></title><description><![CDATA[description 4 uses some <strong>html</strong>]]></description><link>http://example.com/article4?this&that</link><guid isPermaLink="true">http://example.com/article4?this&that</guid><dc:creator><![CDATA[Guest Author]]></dc:creator><pubDate>Sun, 27 May 2012 04:00:00 GMT</pubDate></item><item><title><![CDATA[item 5 & test for categories]]></title><description><![CDATA[description 5]]></description><link>http://example.com/article5</link><guid isPermaLink="true">http://example.com/article5</guid><category><![CDATA[Category 1]]></category><category><![CDATA[Category 2]]></category><category><![CDATA[Category 3]]></category><category><![CDATA[Category 4]]></category><dc:creator><![CDATA[Guest Author]]></dc:creator><pubDate>Mon, 28 May 2012 04:00:00 GMT</pubDate></item></channel></rss>';
|
||||||
var result = feed.xml();
|
var result = feed.xml();
|
||||||
|
|
||||||
test.equal(result.length, expectedResult.length);
|
test.equal(result.length, expectedResult.length);
|
||||||
@@ -94,9 +102,17 @@ module.exports = {
|
|||||||
url: 'http://example.com/article4?this&that',
|
url: 'http://example.com/article4?this&that',
|
||||||
author: 'Guest Author',
|
author: 'Guest Author',
|
||||||
date: 'May 27, 2012 04:00:00 GMT'
|
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 = '<?xml version="1.0" encoding="UTF-8"?>\n<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[title]]></title><description><![CDATA[description]]></description><link>http://example.com</link><generator>NodeJS RSS Module</generator><lastBuildDate>' + new Date().toUTCString() +'</lastBuildDate><atom:link href="http://example.com/rss.xml" rel="self" type="application/rss+xml"/><item><title><![CDATA[item 1]]></title><description><![CDATA[description 1]]></description><link>http://example.com/article1</link><guid isPermaLink="true">http://example.com/article1</guid><dc:creator><![CDATA[Dylan Greene]]></dc:creator><pubDate>Thu, 24 May 2012 04:00:00 GMT</pubDate></item><item><title><![CDATA[item 2]]></title><description><![CDATA[description 2]]></description><link>http://example.com/article2</link><guid isPermaLink="true">http://example.com/article2</guid><dc:creator><![CDATA[Dylan Greene]]></dc:creator><pubDate>Fri, 25 May 2012 04:00:00 GMT</pubDate></item><item><title><![CDATA[item 3]]></title><description><![CDATA[description 3]]></description><link>http://example.com/article3</link><guid isPermaLink="false">item3</guid><dc:creator><![CDATA[Dylan Greene]]></dc:creator><pubDate>Sat, 26 May 2012 04:00:00 GMT</pubDate></item><item><title><![CDATA[item 4 & html test with <strong>]]></title><description><![CDATA[description 4 uses some <strong>html</strong>]]></description><link>http://example.com/article4?this&that</link><guid isPermaLink="true">http://example.com/article4?this&that</guid><dc:creator><![CDATA[Guest Author]]></dc:creator><pubDate>Sun, 27 May 2012 04:00:00 GMT</pubDate></item></channel></rss>';
|
var expectedResult = '<?xml version="1.0" encoding="UTF-8"?>\n<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[title]]></title><description><![CDATA[description]]></description><link>http://example.com</link><generator>NodeJS RSS Module</generator><lastBuildDate>' + new Date().toUTCString() +'</lastBuildDate><atom:link href="http://example.com/rss.xml" rel="self" type="application/rss+xml"/><item><title><![CDATA[item 1]]></title><description><![CDATA[description 1]]></description><link>http://example.com/article1</link><guid isPermaLink="true">http://example.com/article1</guid><dc:creator><![CDATA[Dylan Greene]]></dc:creator><pubDate>Thu, 24 May 2012 04:00:00 GMT</pubDate></item><item><title><![CDATA[item 2]]></title><description><![CDATA[description 2]]></description><link>http://example.com/article2</link><guid isPermaLink="true">http://example.com/article2</guid><dc:creator><![CDATA[Dylan Greene]]></dc:creator><pubDate>Fri, 25 May 2012 04:00:00 GMT</pubDate></item><item><title><![CDATA[item 3]]></title><description><![CDATA[description 3]]></description><link>http://example.com/article3</link><guid isPermaLink="false">item3</guid><dc:creator><![CDATA[Dylan Greene]]></dc:creator><pubDate>Sat, 26 May 2012 04:00:00 GMT</pubDate></item><item><title><![CDATA[item 4 & html test with <strong>]]></title><description><![CDATA[description 4 uses some <strong>html</strong>]]></description><link>http://example.com/article4?this&that</link><guid isPermaLink="true">http://example.com/article4?this&that</guid><dc:creator><![CDATA[Guest Author]]></dc:creator><pubDate>Sun, 27 May 2012 04:00:00 GMT</pubDate></item><item><title><![CDATA[item 5 & test for categories]]></title><description><![CDATA[description 5]]></description><link>http://example.com/article5</link><guid isPermaLink="true">http://example.com/article5</guid><category><![CDATA[Category 1]]></category><category><![CDATA[Category 2]]></category><category><![CDATA[Category 3]]></category><category><![CDATA[Category 4]]></category><dc:creator><![CDATA[Guest Author]]></dc:creator><pubDate>Mon, 28 May 2012 04:00:00 GMT</pubDate></item></channel></rss>';
|
||||||
var result = feed.xml();
|
var result = feed.xml();
|
||||||
|
|
||||||
test.equal(result.length, expectedResult.length);
|
test.equal(result.length, expectedResult.length);
|
||||||
|
|||||||
Reference in New Issue
Block a user