Class: Onebox::Layout

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

Constant Summary collapse

VERSION =
"1.0.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TemplateSupport

#load_paths, #template?

Constructor Details

#initialize(name, record, cache) ⇒ 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

#cacheObject (readonly)

Returns the value of attribute cache


9
10
11
# File 'lib/onebox/layout.rb', line 9

def cache
  @cache
end

#recordObject (readonly)

Returns the value of attribute record


10
11
12
# File 'lib/onebox/layout.rb', line 10

def record
  @record
end

#viewObject (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_htmlObject


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