I want to use compiled jade templates on client side. How should I compile them to get javascript files ? https://github.com/visionmedia/jade
Jade is designed primarily for server-side templating in node.
Jade is an elegant templating engine, primarily used for server-side templating in NodeJS. In plain words, Jade gives you a powerful new way to write markup, with a number of advantages over plain HTML.
Yes you can! https://github.com/techpines/asset-rack#jadeasset
I just open sourced "asset-rack", a nodejs project that can can precompile jade templates and serve them in the browser as javascript functions.
This means that rendering is blazingly fast, even faster then micro-templates because there is no compilation step in the browser.
First you set it up on the server as follows:
new JadeAsset({
url: '/templates.js',
dirname: __dirname + '/templates'
});
If you template directory looked like this:
templates/
navbar.jade
user.jade
footer.jade
Then all your templates come into the browser under the variable "Templates":
$('body').append(Templates.navbar());
$('body').append(Templates.user({name: 'mike', occupation: 'sailor'});
$('body').append(Templates.footer());
#coffeescript
jade = require 'jade'
data = '#menu'
options =
client: true
compileDebug: false
fn = jade.compile data, options
console.log fn.toString()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With