Module: Olelo::Templates
- Included in:
- ApplicationHelper
- Defined in:
- lib/olelo/templates.rb
Class Attribute Summary collapse
-
.cache ⇒ Object
readonly
Returns the value of attribute cache.
-
.loader ⇒ Object
Returns the value of attribute loader.
Class Method Summary collapse
Instance Method Summary collapse
Class Attribute Details
.cache ⇒ Object (readonly)
Returns the value of attribute cache.
4 5 6 |
# File 'lib/olelo/templates.rb', line 4 def cache @cache end |
.loader ⇒ Object
Returns the value of attribute loader.
5 6 7 |
# File 'lib/olelo/templates.rb', line 5 def loader @loader end |
Class Method Details
.enable_caching ⇒ Object
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, = {}, &block) locals = .delete(:locals) || {} name = "#{name}.slim" id = [name, .to_a].flatten.join('-') template = Templates.with_caching(id) do Slim::Template.new(name, ) { Templates.loader.call(name) } end template.render(self, locals, &block).html_safe end |