commit 416979ce72a94658b305028594672027ede5cc5a Author: Dylan Greene Date: Wed Apr 13 00:01:32 2011 -0400 first checkin diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2118699 --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +(The MIT License) + +Copyright (c) 2011 Dylan Greene + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..486f203 --- /dev/null +++ b/index.js @@ -0,0 +1 @@ +module.exports = require('./lib/rss.js'); \ No newline at end of file diff --git a/lib/rss.js b/lib/rss.js new file mode 100644 index 0000000..9bb753b --- /dev/null +++ b/lib/rss.js @@ -0,0 +1,119 @@ +/* + Documentation coming soon. +*/ + +var XML = require('xml'), + log = require('logging').from(__filename); + +function RSS () { + + var site = { + title: '', + url: '', + description: '' + }; + + var feed = { + url: '' + }; + + var author = { + + }; + + + var rss = { + title: '', + description: '', + link: '', + author: { + name: 'string', + uri: 'uri', + email: 'email' + }, + image: { + url: 'url', + title: 'text', + link: 'url' + }, + items: [] + }; + + Object.defineProperty(this, "items", { + get : function(){ return rss.items; }, + set : function(new_items){ rss.items = new_items; }, + enumerable : true + }); + + + + this.item = function (item) { + + item = item || { + title: 'cdata', + link: 'url', + source: 'source', + description: 'cdata', + categories: ['category'], + guid: { permaLink: true, guid: 'guid'}, + comments: 'comments', + author: 'author', + date: new Date() + }; + + rss.items.push(item); + }; + + this.xml = function(indent) { + return '\n' + XML(generateXML(rss), indent); + } + +} + + +function generateXML (rss){ + // todo: xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" + + var channel = [ + { title: rss.title }, + { description: rss.description }, + { generator: 'NodeJS RSS Module' }, + { 'atom:link': { _attr: { href: rss.url, rel: 'self', type: 'application/rss+xml' } } }, + { link: rss.link }, + { updated: new Date().toISOString() }, + { author: [ + { name: rss.author.name}, + { uri: rss.author.uri }, + { email: rss.author.email } + ]} + ]; + + rss.items.forEach(function(item) { + + //TODO: categories + + channel.push({ item: [ + { title: { _cdata: item.title } }, + { link: item.link }, + { guid: [ { _attr: { isPermaLink: item.guid.permaLink } }, item.guid.guid ] }, + { comments: item.comments }, + { description: { _cdata: item.description } }, + { 'dc:creator': { _cdata: item.author } }, + { pubDate: item.date.toISOString() } + ]}); + }); + + return { rss: [ + { _attr: { + '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: channel } + ] }; +} + + + +module.exports = RSS; diff --git a/lib/util.js b/lib/util.js new file mode 100644 index 0000000..e69de29 diff --git a/package.json b/package.json new file mode 100644 index 0000000..fa54c4d --- /dev/null +++ b/package.json @@ -0,0 +1,31 @@ +{ + "name": "rss", + "version": "0.0.1", + "description": "RSS feed generator. A really simple API to add RSS feeds to any project.", + "homepage": "http://github.com/dylang/node-rss", + "author": "Dylan Greene ", + "contributors": [ + "Dylan Greene " + ], + "repository": + { + "type": "git", + "url": "http://github.com/dylang/node-rss" + }, + "bugs": + { + "mail": "dylang@gmail.com", + "web": "http://github.com/dylang/node-rss/issues" + }, + "dependencies": + { + "xml": ">= 0.0.4", + "logging": ">= 2.0.0" + }, + "main": "index.js", + "engines": { "node": ">=0.4.0" }, + "licenses" : + [ + { "type" : "MIT", "url" : "http://github.com/dylang/node-rss/raw/master/LICENSE" } + ] +} \ No newline at end of file diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..2698452 --- /dev/null +++ b/readme.md @@ -0,0 +1,3 @@ +# Node.js library for generating RSS and Atom feeds. + +Documentation coming soon. \ No newline at end of file diff --git a/test/test.js b/test/test.js new file mode 100644 index 0000000..b77a282 --- /dev/null +++ b/test/test.js @@ -0,0 +1,13 @@ +/* + use nodeunit to run tests. +*/ + +var RSS = require('../index'); + +var feed = new RSS(); + +feed.item(); +feed.item(); +feed.item(); + +console.log(feed.xml(true));