lib/musterb/template_handler.rb in musterb-0.0.7 vs lib/musterb/template_handler.rb in musterb-0.1.0

- old
+ new

@@ -1,15 +1,28 @@ require 'musterb' +require 'action_view' -module Musterb::TemplateHandler - def self.render_partial_template(partial) - "render :partial => '#{partial}', :locals => {:initial_context => musterb.context}" +class Musterb::TemplateHandler < Musterb::Musterbifier + def render_partial(partial) + "<%= render :partial => '#{partial}', :locals => {:initial_context => musterb.context} %>" end + def text_without_escaping(tokens) + "<%= #{tokens}.html_safe %>" + end + + def text_with_escaping(tokens) + "<%= #{tokens} %>" + end + + def self.compile_mustache(source, options = {}) + erb = Musterb.to_erb(source, options.merge(:musterbifier_klass => self)) + klass = ActionView::Template::Handlers::ERB + klass.erb_implementation.new(erb, :trim => (klass.erb_trim_mode == "-")).src + end + def self.call(template) - options = {:render_partial_template => method(:render_partial_template)} + options = {} options[:initial_context] = "initial_context" if template.locals.include? "initial_context" - erb = Musterb.to_erb(template.source, options) - klass = ActionView::Template::Handlers::ERB - klass.erb_implementation.new(erb, :trim => (klass.erb_trim_mode == "-")).src + compile_mustache(template.source, options) end end \ No newline at end of file