Created
November 20, 2013 21:51
-
-
Save zaius/7571733 to your computer and use it in GitHub Desktop.
Serving ember templates from rails
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
# Put in config/initializers/handlebars.rb | |
# Add templates to app/assets/javascripts/templates/whatever.js.handlebars | |
# Then require from applicaiton.js (or any manifest) as usual. e.g. | |
# //= require_tree templates | |
class EmberHandlebars < Tilt::Template | |
def self.default_mime_type | |
'application/javascript' | |
end | |
def prepare; end | |
def evaluate scope, locals, &block | |
path = scope.logical_path.gsub /^templates\//, '' | |
<<-JS | |
window.Ember.TEMPLATES["#{path}"] = Ember.Handlebars.compile(#{MultiJson.dump data}); | |
JS | |
end | |
end | |
Sprockets.register_engine '.handlebars', EmberHandlebars |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment