Module: Quintype::Liquid::LiquidTemplateCachingModule

Defined in:
lib/quintype/liquid/liquid_template_caching_module.rb

Constant Summary collapse

QUINTPYE_LIQUID_KEY =
:quintype_liquid_template_cache

Instance Method Summary collapse

Instance Method Details

#compiled_template(template) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/quintype/liquid/liquid_template_caching_module.rb', line 6

def compiled_template(template)
  Thread.current[QUINTPYE_LIQUID_KEY] ||= Hash.new do |m, template|
    Rails.logger.info "Compiling Template"
    m[template] = ::Liquid::Template.parse(template)
  end
  Thread.current[QUINTPYE_LIQUID_KEY][template]
end

#render(template, local_assigns = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/quintype/liquid/liquid_template_caching_module.rb', line 14

def render(template, local_assigns = {})
  @view.controller.headers['Content-Type'] ||= 'text/html; charset=utf-8'

  assigns = if @controller.respond_to?(:liquid_assigns, true)
              @controller.send(:liquid_assigns)
            else
              @view.assigns
            end
  assigns['content_for_layout'] = @view.content_for(:layout) if @view.content_for?(:layout)
  assigns.merge!(local_assigns.stringify_keys)

  liquid = compiled_template(template)
  liquid.send(:render!, assigns, filters: filters, registers: { view: @view, controller: @controller, helper: @helper }).html_safe
end