class Cell::Templates

Gets cached in production.

Public Instance Methods

[](prefixes, view, options) click to toggle source

prefixes could be instance variable as they will never change.

# File lib/cell/templates.rb, line 5
def [](prefixes, view, options)
  find_template(prefixes, view, options)
end

Private Instance Methods

cache() click to toggle source
# File lib/cell/templates.rb, line 11
def cache
  @cache ||= Cache.new
end
create(prefix, view, options) click to toggle source
# File lib/cell/templates.rb, line 22
def create(prefix, view, options)
  # puts "...checking #{prefix}/#{view}"
  return unless File.exist?("#{prefix}/#{view}") # DISCUSS: can we use Tilt.new here?

  template_class = options.delete(:template_class)
  template_class.new("#{prefix}/#{view}", options) # Tilt.new()
end
find_template(prefixes, view, options) click to toggle source
# File lib/cell/templates.rb, line 15
def find_template(prefixes, view, options) # options is not considered in cache key.
  cache.fetch(prefixes, view) do |prefix|
    # this block is run once per cell class per process, for each prefix/view tuple.
    create(prefix, view, options)
  end
end