Skip to content

Instantly share code, notes, and snippets.

@dudleyf
Created December 14, 2011 15:52
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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
@ppcano
Copy link

ppcano commented Dec 14, 2011

why don't create a file which appends:

output.write "Ember.TEMPLATES[filenamewithout_handlebars_extension] =  Ember.Handlebars.compile(#{input.read.to_json})"

On this way, set up the view looks like better.

    Em.View.extend({
        templateName: 'filenamewithout_handlebars_extension'
    })

What i don't really understand is the purpose of minispade????, could you give me a explanation?,

i know i have been using minispade for testing with bpm, but now i don't really get the point if minispade is required or not.

Last day, i could not mount my project with rakepipeline, and so far the hosting was node backend, i deployed my project without rakepipeline and emulate the pipeline behaviour with node tools.

That is the reason, why i am interesting to know which is the purpose of minispade, perhaps i am missing something i don't still know.

@dudleyf
Copy link
Author

dudleyf commented Dec 14, 2011

Minispade just lets you require your javascript in a different order than the order of your js files. If you use minispade you can concatenate all your javascript without worrying about what order the files get included, then use minispade to load what you need when you need it. If you have another way you're comfortable with managing the load order of your javascript, feel free to do that. You don't have to use minispade. You could definitely change the filter to add your templates to Ember.TEMPLATES if you wanted to. I prefer not to, since that means I have to make sure that whatever file that code gets written to gets loaded before the code that uses the template. With minispade, I don't have to worry about what files get loaded first, I just require a module when I need it.

@nicholasjhenry
Copy link

@dudleyf With this method how is a template assigned to a View?

@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