________ _________ __________
______(_)_____ ______ /_______(_)_ /_____
_____ /_ __ `/ __ /_ _ \_ /_ __/ _ \
____ / / /_/ // /_/ / / __/ / / /_ / __/
___ / \__,_/ \__,_/ \___//_/ \__/ \___/
/___/ Compile and render Jade templates from Ruby
Jadeite lets you compile and render Jade templates from your Ruby code. Under the hood it uses the Jade node module running in therubyracer's embedded V8 JavaScript engine.
It is pretty cool since it means you can easily share templates between the server side and front end. Render with json/javascript data on the client side and ruby objects on the server side.
Add this line to your application's Gemfile:
gem 'jadeite'
And then execute:
$ bundle
Or install it yourself as:
$ gem install jadeite
env = Jadeite::Environment.new
env.render('p Hello #{what}!', {:what =>"world"})
#=> "<p>Hello world!</p>"
env = Jadeite::Environment.new
compiled = env.compile('p Hello #{what}!')
compiled.render :what => "world"
#=> "<p>Hello world!</p>"
compiled.render :what => "moon"
#=> "<p>Hello moon!</p>"
env = Jadeite::Environment.new
# compile first
compiled = env.compile_file("./hello.jade")
compiled.render :what => "world"
#=> "<p>Hello world!</p>"
# or simply
env.render_file("./hello.jade", :what => "moon")
#=> "<p>Hello moon!</p>"
env = Jadeite::Environment.new
env.compile 'p Hello #{what}!', :client => true, :compileDebug => false
#=> function anonymous(locals, attrs, escape, rethrow, merge) {
# var attrs = jade.attrs, escape = jade.escape, rethrow = jade.rethrow, merge = jade.merge;
# var buf = [];
# with (locals || {}) {
# var interp;
# buf.push('<p>Hello ' + escape((interp = what) == null ? '' : interp) + '!</p>');
# }
# return buf.join("");
# }
See https://github.com/visionmedia/jade#browser-support for more info.
Instances of Jadeite::Environment has two public methods:
compile(template_string, options)
and render(template_string, data, options)
in where the options
argument for both of them corresponds to the options argument in
Jade's public api.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request