Skip to content

Instantly share code, notes, and snippets.

@dudleyf
Created December 14, 2011 15:52
Show Gist options
  • Save dudleyf/1477124 to your computer and use it in GitHub Desktop.
Save dudleyf/1477124 to your computer and use it in GitHub Desktop.
Handlebars Rake::Pipeline filter
require "json"
class HandlebarsFilter < Rake::Pipeline::Filter
def initialize(&block)
block ||= proc { |input| input.sub(/\.handlebars$/, '.js') }
super(&block)
end
def generate_output(inputs, output)
inputs.each do |input|
output.write "return Ember.Handlebars.compile(#{input.read.to_json})"
end
end
end
@dudleyf
Copy link
Author

dudleyf commented Jan 3, 2012

Given a template in lib/templates/myview.handlebars:

MyView = Ember.View.extend({
  template: minispade.require('lib/templates/myview.js')
})

That's not necessarily the right way to do it, it's just the way I did it :) We'll hopefully have a HandlebarsFilter in rake-pipeline-web-filters fairly soon that will do it the right way.

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