Skip to content

Instantly share code, notes, and snippets.

@seven1m
Created May 24, 2011 22:24
Show Gist options
  • Save seven1m/989891 to your computer and use it in GitHub Desktop.
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
# 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 %>
@devth
Copy link

devth commented Jul 12, 2011

Looks like a good fit for guard

@devth
Copy link

devth commented Jul 13, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment