Class: Onebox::Layout
- Inherits:
-
Mustache
- Object
- Mustache
- Onebox::Layout
- Includes:
- TemplateSupport
- Defined in:
- lib/onebox/layout.rb
Constant Summary collapse
- VERSION =
"1.0.0"
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#record ⇒ Object
readonly
Returns the value of attribute record.
-
#view ⇒ Object
readonly
Returns the value of attribute view.
Instance Method Summary collapse
-
#initialize(name, record, cache) ⇒ Layout
constructor
A new instance of Layout.
- #to_html ⇒ Object
Methods included from TemplateSupport
Constructor Details
#initialize(name, record, cache) ⇒ Layout
Returns a new instance of Layout.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/onebox/layout.rb', line 13 def initialize(name, record, cache) @cache = cache @record = Onebox::Helpers.symbolize_keys(record) # Fix any relative paths if @record[:image] && @record[:image] =~ /^\/[^\/]/ @record[:image] = "#{uri.scheme}://#{uri.host}/#{@record[:image]}" end @md5 = Digest::MD5.new @view = View.new(name, record) @template_name = "_layout" @template_path = load_paths.last end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
9 10 11 |
# File 'lib/onebox/layout.rb', line 9 def cache @cache end |
#record ⇒ Object (readonly)
Returns the value of attribute record.
10 11 12 |
# File 'lib/onebox/layout.rb', line 10 def record @record end |
#view ⇒ Object (readonly)
Returns the value of attribute view.
11 12 13 |
# File 'lib/onebox/layout.rb', line 11 def view @view end |
Instance Method Details
#to_html ⇒ Object
28 29 30 31 32 |
# File 'lib/onebox/layout.rb', line 28 def to_html result = cache.fetch(checksum) { render(details) } cache[checksum] = result if cache.respond_to?(:key?) result end |