Class: Curly::TemplateHandler

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

Class Method Summary collapse

Class Method Details

.cache_if_key_is_not_nil(context, presenter) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/curly/template_handler.rb', line 22

def cache_if_key_is_not_nil(context, presenter)
  if key = presenter.cache_key
    if presenter.class.respond_to?(:cache_key)
      presenter_key = presenter.class.cache_key
    else
      presenter_key = nil
    end

    cache_options = presenter.cache_options || {}
    cache_options[:expires_in] ||= presenter.cache_duration

    context.cache([key, presenter_key].compact, cache_options) do
      yield
    end
  else
    yield
  end
end

.call(template) ⇒ Object

Handles a Curly template, compiling it to Ruby code. The code will be evaluated in the context of an ActionView::Base instance, having access to a number of variables.

template - The ActionView::Template template that should be compiled.

Returns a String containing the Ruby code representing the template.



16
17
18
19
20
# File 'lib/curly/template_handler.rb', line 16

def call(template)
  instrument(template) do
    compile(template)
  end
end