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 %> |
I think Rails only renders the CoffeeScript to JS whenever the file is changed. That's probably why it won't reload. Not sure how to get around that at the moment. Maybe try touching the templates file as a workaround?
Yes, we're doing that but it's proving painful to say the least :)
Cheers
Looks like a good fit for guard
Official support :)
http://news.ycombinator.com/item?id=2760804
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this isn't reloading in development mode. any solution to that?