Module: UzuUzu::Tilt

Defined in:
lib/uzuuzu-core/tilt.rb

Class Method Summary collapse

Class Method Details

.render_engine(instance, view_string, engine = 'erb', options = {}, locals = {}, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/uzuuzu-core/tilt.rb', line 11

def self.render_engine(instance, view_string, engine='erb', options={}, locals={}, &block)
  template = ::Tilt[engine.to_s].new { |t| view_string.force_encoding('UTF-8') }
  contents = template.render(instance, locals, &block)
  unless options.blank?
    layout = options.delete(:layout)
    layout_string = options.delete(:layout_string)
    layout_engine = options.delete(:layout_engine) || engine
    unless layout.blank?
      if ::File.file?(layout)
        layout_string = ::File.respond_to?(:binread) ? ::File.binread(layout) : ::File.read(layout)
      end
    end
    unless layout_string.blank?
      locals[:@contents] = contents
      contents = self.render_engine(instance, layout_string, layout_engine, options, locals)
    end
  end
  contents
end