Skip to content

Instantly share code, notes, and snippets.

@aviflax
Created June 28, 2011 21:15
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 aviflax/1052237 to your computer and use it in GitHub Desktop.
Save aviflax/1052237 to your computer and use it in GitHub Desktop.
Usage patterns for Weld
welder(things, 'things.html', 'thing', function(err, html) {
if (err) throw new Error(err);
res.send(html, {'Content-Type': 'text/html'});
});
var jsdom = require('jsdom'),
weld = require('weld');
module.exports = function(data, templateName, className, callback) {
jsdom.env('templates/' + templateName, function(err, window) {
if (err)
return callback(err);
var templateElement = window.document.getElementsByClassName(className)[0];
if (!templateElement)
return callback('Template element of class ' + className + ' not found.');
weld.weld(templateElement, data);
callback(null, window.document.outerHTML);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment