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
# File 'lib/musterb/template_handler.rb', line 17

def self.build_initial_context(locals)
  "Musterb::RailsLocalsExtractor.new(#{locals.inspect}, binding, Musterb::InstanceVariableExtractor.new(self,  Musterb::BindingExtractor.new(binding)))"
end

.call(template) ⇒ Object



21
22
23
24
25
26
# File 'lib/musterb/template_handler.rb', line 21

def self.call(template)
  initial_context = template.locals.include?("initial_context") ? "initial_context" : build_initial_context(template.locals.map(&:to_s) - ["initial_context"])
  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