Add scripts to create myops-getqueryview:
[myops.git] / web / query / vendor / couchapp / lib / atom.js
1 // atom feed generator
2 // requries E4X support.
3
4 function f(n) {    // Format integers to have at least two digits.
5     return n < 10 ? '0' + n : n;
6 }
7
8 function rfc3339(date) {
9   return date.getUTCFullYear()   + '-' +
10     f(date.getUTCMonth() + 1) + '-' +
11     f(date.getUTCDate())      + 'T' +
12     f(date.getUTCHours())     + ':' +
13     f(date.getUTCMinutes())   + ':' +
14     f(date.getUTCSeconds())   + 'Z';
15 };
16
17 exports.header = function(data) {
18   var f = <feed xmlns="http://www.w3.org/2005/Atom"/>;
19   f.title = data.title;
20   f.id = data.feed_id;
21   f.link.@href = data.feed_link;
22   f.link.@rel = "self";
23   f.generator = "CouchApp on CouchDB";
24   f.updated = rfc3339(data.updated);
25   return f.toXMLString().replace(/\<\/feed\>/,'');
26 };
27
28 exports.entry = function(data) {
29   var entry = <entry/>;
30   entry.id = data.entry_id;
31   entry.title = data.title;
32   entry.content = data.content;
33   entry.content.@type = (data.content_type || 'html');
34   entry.updated = rfc3339(data.updated);
35   entry.author = <author><name>{data.author}</name></author>;
36   entry.link.@href = data.alternate;
37   entry.link.@rel = "alternate";
38   return entry;
39 }