Class: Embarista::Filters::PrecompileHandlebarsFilter
- Inherits:
-
Rake::Pipeline::Filter
- Object
- Rake::Pipeline::Filter
- Embarista::Filters::PrecompileHandlebarsFilter
- Defined in:
- lib/embarista/filters/precompile_handlebars_filter.rb
Instance Method Summary collapse
- #default_ember_template_compiler_src ⇒ Object
- #default_handlebars_src ⇒ Object
- #generate_output(inputs, output) ⇒ Object
-
#initialize(options = {}, &block) ⇒ PrecompileHandlebarsFilter
constructor
A new instance of PrecompileHandlebarsFilter.
Constructor Details
#initialize(options = {}, &block) ⇒ PrecompileHandlebarsFilter
Returns a new instance of PrecompileHandlebarsFilter.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/embarista/filters/precompile_handlebars_filter.rb', line 4 def initialize(={}, &block) @template_dir = [:template_dir] || 'templates' @templates_global = [:templates_global] || 'Ember.TEMPLATES' [:handlebars] ||= [:ember_template_compiler] ||= default_ember_template_compiler_src throw Embarista::PrecompilerConfigurationError.new('Must specify handlebars source path') unless [:handlebars] throw Embarista::PrecompilerConfigurationError.new('Must specify ember_template_compiler source path') unless [:ember_template_compiler] @handlebars_src = [:handlebars] @ember_template_compiler_src = [:ember_template_compiler] super(&block) unless block_given? @output_name_generator = proc { |input| input.sub(/\.handlebars$/, '.js') } end end |
Instance Method Details
#default_ember_template_compiler_src ⇒ Object
41 42 43 |
# File 'lib/embarista/filters/precompile_handlebars_filter.rb', line 41 def default_ember_template_compiler_src Dir['app/vendor/ember-template-compiler-*.js'].last end |
#default_handlebars_src ⇒ Object
37 38 39 |
# File 'lib/embarista/filters/precompile_handlebars_filter.rb', line 37 def Dir['app/vendor/handlebars-*'].last end |
#generate_output(inputs, output) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/embarista/filters/precompile_handlebars_filter.rb', line 23 def generate_output(inputs, output) inputs.each do |input| name = File.basename(input.path, '.handlebars') dirname = File.dirname(input.path) dirname.gsub!(/^\/?#{@template_dir}\/?/,'') full_name = [dirname, name].compact.reject(&:empty?).join('/') compiled = precompile(input.read, @handlebars_src, @ember_template_compiler_src) output.write "\n#{@templates_global}['#{full_name}'] = #{compiled};\n" end end |