Class: Slimmer::ComponentResolver

Inherits:
ActionView::Resolver
  • Object
show all
Defined in:
lib/slimmer/component_resolver.rb

Constant Summary collapse

TEST_TAG_NAME =
'test-govuk-component'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.cachingObject



8
9
10
11
12
# File 'lib/slimmer/component_resolver.rb', line 8

def self.caching
  # this turns off the default ActionView::Resolver caching which caches
  # all templates for the duration of the current process in production
  false
end

Instance Method Details

#find_templates(name, prefix, partial, details, outside_app_allowed = false) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/slimmer/component_resolver.rb', line 14

def find_templates(name, prefix, partial, details, outside_app_allowed = false)
  return [] unless prefix == 'govuk_component'
  cache = Cache.instance

  template_path = [prefix, name].join('/')
  if test?
    template_body = test_body(template_path)
  else
    template_body = cache.fetch(template_path) do
      fetch(template_url(template_path))
    end
  end

  details = {
    :format => 'text/html',
    :updated_at => Time.now,
    :virtual_path => template_path
  }

  [ActionView::Template.new(template_body, template_path, erb_handler, details)]
end