module Olelo::Templates

Attributes

cache[R]
loader[RW]

Public Class Methods

enable_caching() click to toggle source
# File lib/olelo/templates.rb, line 7
def enable_caching
  @cache = {}
end
with_caching(id) { || ... } click to toggle source
# File lib/olelo/templates.rb, line 11
def with_caching(id)
  return cache[id] if cache && cache[id]
  template = yield
  cache[id] = template if cache
  template
end

Public Instance Methods

render(name, options = {}, &block) click to toggle source
# File lib/olelo/templates.rb, line 19
def render(name, options = {}, &block)
  locals = options.delete(:locals) || {}
  name = "#{name}.slim"
  id = [name, options.to_a].flatten.join('-')
  template = Templates.with_caching(id) do
    Slim::Template.new(name, options) { Templates.loader.call(name) }
  end
  template.render(self, locals, &block).html_safe
end