Skip to content

Instantly share code, notes, and snippets.

@danielbeardsley
Created June 22, 2011 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save danielbeardsley/1041060 to your computer and use it in GitHub Desktop.
Save danielbeardsley/1041060 to your computer and use it in GitHub Desktop.
A template renderer for express.js that processes plain vanilla HTML and has the option to strip newlines.
// Usage:
// express_app.register('html', htmlRenderer({stripNewlines: true}));
// ...
// express_app.get('/plain', function(req, res){
// res.render('./path_to_html_file');
// })
function htmlRenderer(opt){
var stripNewlines = opt && opt.stripNewlines;
return {
compile: function(str, view_options){
if(stripNewlines) str = str.replace(/[\n\r]+/, ' ');
return function(locals){
return str;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment