Created
December 22, 2012 15:42
-
-
Save egaumer/4359475 to your computer and use it in GitHub Desktop.
Example of how to generate Atom feeds with E4X.
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
/* the controller */ | |
function blog() { | |
function toAtom(results) { | |
default xml namespace = "http://www.w3.org/2005/Atom"; | |
var feed = <feed/>; | |
feed.id = "http://host.com/feeds/blog/atom"; | |
feed.title = "Sample Atom Feed"; | |
feed.author.name = "Jon Smith"; | |
feed.author.email = "[email protected]"; | |
feed.entry = new XMLList(); | |
_.each(results.hits.hits, function(hit) { | |
var entry = <entry/>; | |
entry.id = hit._id; | |
entry.title = hit._source.title; | |
entry.content = hit._source.teaser; | |
entry.published = hit._source.date; | |
feed.entry += entry; | |
}); | |
return feed.toString(); | |
} | |
function search(query) { | |
return evo.Request() | |
.indicies("demos") | |
.types("blogpost") | |
.query(evo.QueryStringQuery(query)) | |
.doSearch(toAtom); | |
} | |
return { | |
/* the action */ | |
atom: function(request) { | |
var query = request.params.q || "*"; | |
return { | |
status: 200, | |
headers: {"Content-Type": "text/xml"}, | |
body: search(query) | |
}; | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment