Class: Embarista::Precompiler
- Inherits:
-
Object
- Object
- Embarista::Precompiler
- Defined in:
- lib/embarista/precompiler.rb
Instance Attribute Summary collapse
-
#ember_template_precompiler ⇒ Object
readonly
Returns the value of attribute ember_template_precompiler.
-
#handlebars ⇒ Object
readonly
Returns the value of attribute handlebars.
Instance Method Summary collapse
- #compile(template) ⇒ Object
-
#initialize(opts) ⇒ Precompiler
constructor
A new instance of Precompiler.
- #precompiler ⇒ Object
- #sources ⇒ Object
Constructor Details
#initialize(opts) ⇒ Precompiler
Returns a new instance of Precompiler.
27 28 29 30 31 32 |
# File 'lib/embarista/precompiler.rb', line 27 def initialize(opts) throw PrecompilerConfigurationError.new('Must specify handlebars source path') unless opts[:handlebars] throw PrecompilerConfigurationError.new('Must specify ember_template_compiler source path') unless opts[:ember_template_compiler] @handlebars = File.new(opts[:handlebars]) @ember_template_precompiler = File.new(opts[:ember_template_compiler]) end |
Instance Attribute Details
#ember_template_precompiler ⇒ Object (readonly)
Returns the value of attribute ember_template_precompiler.
47 48 49 |
# File 'lib/embarista/precompiler.rb', line 47 def ember_template_precompiler @ember_template_precompiler end |
#handlebars ⇒ Object (readonly)
Returns the value of attribute handlebars.
47 48 49 |
# File 'lib/embarista/precompiler.rb', line 47 def @handlebars end |
Instance Method Details
#compile(template) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/embarista/precompiler.rb', line 34 def compile(template) context.call( "EmberHandlebarsCompiler.precompile", sanitize(template) ) rescue ExecJS::ProgramError => ex raise Embarista::PrecompilerError.new(template, ex) end |
#precompiler ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/embarista/precompiler.rb', line 49 def precompiler @precompiler ||= StringIO.new(<<-JS) var exports = this.exports || {}; function require() { // ember-template-compiler only requires('handlebars') return Handlebars; } // Precompiler var EmberHandlebarsCompiler = { precompile: function(string) { return exports.precompile(string).toString(); } }; JS end |
#sources ⇒ Object
43 44 45 |
# File 'lib/embarista/precompiler.rb', line 43 def sources [precompiler, , ember_template_precompiler] end |