Module: Olelo::Templates

Included in:
ApplicationHelper
Defined in:
lib/olelo/templates.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.cacheObject (readonly)

Returns the value of attribute cache.



4
5
6
# File 'lib/olelo/templates.rb', line 4

def cache
  @cache
end

.loaderObject

Returns the value of attribute loader.



5
6
7
# File 'lib/olelo/templates.rb', line 5

def loader
  @loader
end

Class Method Details

.enable_cachingObject



7
8
9
# File 'lib/olelo/templates.rb', line 7

def enable_caching
  @cache = {}
end

.with_caching(id) ⇒ Object



11
12
13
14
15
16
# 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

Instance Method Details

#render(name, options = {}, &block) ⇒ Object



19
20
21
22
23
24
25
26
27
# 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