lib/steering.rb in steering-1.0.0 vs lib/steering.rb in steering-1.1.0
- old
+ new
@@ -46,9 +46,18 @@
def compile(template)
template = template.read if template.respond_to?(:read)
Source.context.call("Handlebars.precompile", template, { :knownHelpers => known_helpers })
end
+ def compile_to_file(template, file, extension = ".handlebars")
+ 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")
+ end
+ end
+
def context_for(template, extra = "")
ExecJS.compile("#{Source.runtime}; #{extra}; var template = Handlebars.template(#{compile(template)})")
end
def known_helpers