Class: Musterb::TemplateHandler

Inherits:
Musterbifier show all
Defined in:
lib/musterb/template_handler.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Musterbifier

#block_end, #block_if, #block_unless, #change_token, #comment, #fetch, #initialize, #to_erb

Constructor Details

This class inherits a constructor from Musterb::Musterbifier

Class Method Details

.build_initial_context(locals) ⇒ Object



17
18
19
20
21
# File 'lib/musterb/template_handler.rb', line 17

def self.build_initial_context(locals)
  return "initial_context" if locals.include?("initial_context")
  return "Musterb::ExtractValues.new_context(mustache)" if locals.include?("mustache")
  "Musterb::RailsLocalsExtractor.new(#{locals.inspect}, binding, Musterb::InstanceVariableExtractor.new(self, Musterb::NullExtractor.new))"
end

.call(template) ⇒ Object



23
24
25
26
27
28
# File 'lib/musterb/template_handler.rb', line 23

def self.call(template)
  initial_context = build_initial_context(template.locals.map(&:to_s))
  erb = Musterb.to_erb(template.source, :musterbifier_klass => self, :initial_context => initial_context)
  klass = ActionView::Template::Handlers::ERB
  klass.erb_implementation.new(erb, :trim => (klass.erb_trim_mode == "-")).src
end

Instance Method Details

#render_partial(partial) ⇒ Object



5
6
7
# File 'lib/musterb/template_handler.rb', line 5

def render_partial(partial)
  "<%= render :partial => '#{partial}', :locals => {:initial_context => musterb.context} %>"
end

#text_with_escaping(tokens) ⇒ Object



13
14
15
# File 'lib/musterb/template_handler.rb', line 13

def text_with_escaping(tokens)
  "<%= #{tokens} %>"
end

#text_without_escaping(tokens) ⇒ Object



9
10
11
# File 'lib/musterb/template_handler.rb', line 9

def text_without_escaping(tokens)
  "<%= #{tokens}.html_safe %>"
end