Class: LiquidAssets::TemplateHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/liquid_assets/template_handler.rb

Class Method Summary collapse

Class Method Details

.call(template) ⇒ Object



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

def self.call(template)
    dump = Marshal.dump( LiquidAssets.parse( template ) )
    return "LiquidAssets::TemplateHandler.render(#{dump.inspect}, self, local_assigns)"
end

.render(src, view, local_assigns) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/liquid_assets/template_handler.rb', line 13

def self.render( src, view, local_assigns )
    view.controller.headers["Content-Type"] ||= 'text/html; charset=utf-8'

    assigns = view.assigns.dup
    assigns.merge!( local_assigns.stringify_keys )

    if content = view.content_for?(:layout)
        assigns["content_for_layout"] = content
    end

    Marshal.load( src ).render( assigns, :registers=>{
            :action_view => view,
            :controller  => view.controller
        } ).html_safe
end