Created
October 21, 2011 22:14
-
-
Save andrewsardone/1305119 to your computer and use it in GitHub Desktop.
CouchDB list function for an icalendar format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://localhost:5984/db/_design/doc/_list/ics/events | |
// | |
// HTTP/1.1 200 OK | |
// Vary: Accept | |
// Transfer-Encoding: chunked | |
// Server: CouchDB/1.1.0 (Erlang OTP/R14B03) | |
// Etag: "6A5G0HZINBK0F6S0NSE7KHM2M" | |
// Date: Fri, 21 Oct 2011 22:11:15 GMT | |
// Content-Type: text/calendar | |
// | |
// BEGIN:VCALENDAR | |
// VERSION:2.0 | |
// PRODID:Calendar | |
// BEGIN:VEVENT | |
// ... | |
// END:VEVENT | |
// END:VCALENDAR | |
ddoc.lists = { | |
ics: function(head, req) { | |
var Mustache = require("lib/mustache"); | |
var template = "" + | |
"BEGIN:VCALENDAR\n" + | |
"VERSION:2.0\n" + | |
"PRODID:Fact-Checker\n" + | |
"{{#events}}\n" + | |
"BEGIN:VEVENT\n" + | |
"UID:{{uid}}\n" + | |
"DTSTAMP:{{updated_at}}\n" + | |
"DTSTART:{{start_time}}\n" + | |
"DTEND:{{end_time}}\n" + | |
"SUMMARY:{{summary}}\n" + | |
"END:VEVENT\n" + | |
"{{/events}}\n" + | |
"END:VCALENDAR\n"; | |
provides("ics", function() { | |
var rows = []; | |
while(r = getRow()) { | |
rows.push({ | |
uid: r._id, | |
updated_at: r.updated_at, | |
start_time: r.start_time, | |
end_time: r.end_time, | |
summary: r.summary | |
}); | |
} | |
var ics = Mustache.to_html(template, {events: rows}); | |
return ics; | |
}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment