first checkin

This commit is contained in:
Dylan Greene committed 2011-04-13 00:01:32 -04:00
commit 416979ce72
7 files changed
+189

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
(The MIT License)
Copyright (c) 2011 Dylan Greene <dylang@gmail.com>
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.
+1
View File
@@ -0,0 +1 @@
module.exports = require('./lib/rss.js');
+119
View File
@@ -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 '<?xml version="1.0" encoding="UTF-8"?>\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;
View File
Whitespace-only changes.
+31
View File
@@ -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 <dylang@gmail.com>",
"contributors": [
"Dylan Greene <dylang@gmail.com>"
],
"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" }
]
}
+3
View File
@@ -0,0 +1,3 @@
# Node.js library for generating RSS and Atom feeds.
Documentation coming soon.
+13
View File
@@ -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));