Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
This gem adds jsRender (next generation of jQuery Templates) and a corresponding Sprockets engine to the asset pipeline for Rails >= 3.1 applications.
Ruby Perl
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
spec
vendor/assets/javascripts
.gitignore
Gemfile
LICENSE
README.md
Rakefile
jsrender-rails.gemspec

README.md

jsRender-rails

This gem adds jsRender (next generation of jQuery Templates) and a corresponding Sprockets engine to the asset pipeline for Rails >= 3.1 applications.

Installation

Add it to your Gemfile and run bundle or run gem install jsrender-rails.

Usage

jsRender tempaltes will be recognized by Sprockets with the .tmpl extension. Place them anywhere in the Sprockets load path.

<!-- app/assets/javascripts/views/user.tmpl -->
<div class="user">{{>name}}</div>

In your JavaScript manifest file, require jsRender followed by your folder containing all your templates/views. The templates are compiled and named with their Sprockets logical path:

<!-- app/assets/javascripts/application.js -->
//= require jsrender
//= require_tree ./views

$(body).append($.render["views/user"]({name:"Sebastian Pape"}));

Configuration

If the path to all of your views/templates have a common prefix that you prefer is not included in the template's name, you can set this option in config/application.rb:

config.jsRender.prefix = "views"

That would change the previous example to this:

$(body).append($.render["user"]({name:"Sebastian Pape"}));

The prefix can also be a regular expression. For example, to use only the name of the file for the template name, regardless of directory structure:

config.jsRender.prefix = %r{([^/]*/)*}

Compatible with jQuery Templates?

For sure NOT!

HAML

If you like to use haml in your jsRender templates I highly recommend haml_assets.

Acknowledgements

jsRender was created by Boris Moore.

The idea to easily adding jQuery templates to the Rails Asset-Pipeline comes from jimmycuadra/jquery-tmpl-rails and was adopted here to work with jsRender.

The Sprockets engine was originally derived from the sprockets-jquery-tmpl gem. If you want a similar mechanism for use outside of Rails, take a look at this project.

Something went wrong with that request. Please try again.