public
Created

Handlebars Rake::Pipeline filter

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13
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

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.

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.

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

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.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.