Class: Onebox::Layout

Inherits:
Mustache
  • Object
show all
Defined in:
lib/onebox/layout.rb

Constant Summary collapse

VERSION =
"1.0.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, record, cache) ⇒ Layout

Returns a new instance of Layout.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/onebox/layout.rb', line 9

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

#cacheObject (readonly)

Returns the value of attribute cache.



5
6
7
# File 'lib/onebox/layout.rb', line 5

def cache
  @cache
end

#recordObject (readonly)

Returns the value of attribute record.



6
7
8
# File 'lib/onebox/layout.rb', line 6

def record
  @record
end

#viewObject (readonly)

Returns the value of attribute view.



7
8
9
# File 'lib/onebox/layout.rb', line 7

def view
  @view
end

Instance Method Details

#to_htmlObject



24
25
26
27
28
# File 'lib/onebox/layout.rb', line 24

def to_html
  result = cache.fetch(checksum) { render(details) }
  cache[checksum] = result if cache.respond_to?(:key?)
  result
end