lib/steering.rb in steering-1.1.1 vs lib/steering.rb in steering-1.2.0

- old
+ new

@@ -46,16 +46,25 @@ 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") + def compile_to_file(template, file, options = {}) + if options.is_a?(String) + extension = options + partial = false + else + extension = options[:extension] || ".handlebars" + partial = options[: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 def context_for(template, extra = "") ExecJS.compile("#{Source.runtime}; #{extra}; var template = Handlebars.template(#{compile(template)})") @@ -63,10 +72,12 @@ def known_helpers Source.known_helpers end - def render(template, locals = {}) - context_for(template).call("template", locals) + 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 end end