Created
June 28, 2011 21:15
-
-
Save aviflax/1052237 to your computer and use it in GitHub Desktop.
Usage patterns for Weld
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
welder(things, 'things.html', 'thing', function(err, html) { | |
if (err) throw new Error(err); | |
res.send(html, {'Content-Type': 'text/html'}); | |
}); |
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
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