Created
May 24, 2011 22:24
-
-
Save seven1m/989891 to your computer and use it in GitHub Desktop.
Render ERB JS templates with Underscore.js and Sprockets and Tilt in Rails 3.1
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
# creates a global JST object containing all the templates | |
# 1. install Tilt in your Gemspec | |
# 2. Paste this in a file at app/assets/javascripts/templates.js.coffee.erb | |
# 3. `require` the templates file from your main js include file. | |
# 4. Put your templates at app/views/whatever/my_template.html.jst | |
window.JST = | |
<% Dir[Rails.root.join('app/views/**/*.jst')].each do |path| %> | |
<%= path.match(%r{/([^/]+)\.html\.jst$})[1] %>: _.template(<%= File.read(path).inspect.gsub(/\r?\n/, '') %>) | |
<% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like a good fit for guard