Skip to content

Instantly share code, notes, and snippets.

@egaumer
Created December 22, 2012 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save egaumer/4359475 to your computer and use it in GitHub Desktop.
Save egaumer/4359475 to your computer and use it in GitHub Desktop.
Example of how to generate Atom feeds with E4X.
/* 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 = "jsmith@host.com";
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