Module: Steering
- Defined in:
- lib/steering.rb,
lib/steering/version.rb
Defined Under Namespace
Modules: Source
Constant Summary collapse
- VERSION =
"1.3.0"
Class Method Summary collapse
- .compile(template) ⇒ Object
- .compile_to_file(template, file, options = {}) ⇒ Object
- .context_for(template, extra = "") ⇒ Object
- .known_helpers ⇒ Object
- .render(template, *args) ⇒ Object
- .version ⇒ Object
Class Method Details
.compile(template) ⇒ Object
46 47 48 49 |
# File 'lib/steering.rb', line 46 def compile(template) template = template.read if template.respond_to?(:read) Source.context.call("Handlebars.precompile", template, { :knownHelpers => known_helpers }) end |
.compile_to_file(template, file, options = {}) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/steering.rb', line 51 def compile_to_file(template, file, = {}) if .is_a?(String) extension = partial = false else extension = [:extension] || ".handlebars" partial = [:partial] || false end File.open(file, 'w') do |f| name = File.basename(template, extension) template = File.read(template) f.write("\nHandlebars.templates = Handlebars.templates || {};") f.write("\nHandlebars.templates['#{name}'] = Handlebars.template(#{compile(template)});\n") f.write("Handlebars.registerPartial('#{name}', Handlebars.templates['#{name}']);\n") if partial end end |
.context_for(template, extra = "") ⇒ Object
69 70 71 |
# File 'lib/steering.rb', line 69 def context_for(template, extra = "") ExecJS.compile("#{Source.runtime}; #{extra}; var template = Handlebars.template(#{compile(template)})") end |
.known_helpers ⇒ Object
73 74 75 |
# File 'lib/steering.rb', line 73 def known_helpers Source.known_helpers end |
.render(template, *args) ⇒ Object
77 78 79 80 81 |
# File 'lib/steering.rb', line 77 def render(template, *args) locals = args.last.is_a?(Hash) ? args.pop : {} extra = args.first.to_s context_for(template, extra).call("template", locals) end |