Class: Curlybars::TemplateHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/curlybars/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
40
41
42
# File 'lib/curlybars/template_handler.rb', line 22

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

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

    # Curlybars doesn't allow Rails to handle the template digest.
    # So, we disable it.
    cache_options[:skip_digest] = true

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

.call(template, source) ⇒ Object

Handles a Curlybars 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/curlybars/template_handler.rb', line 16

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