class Onebox::Layout

Constants

VERSION

Attributes

record[R]
view[R]

Public Class Methods

new(name, record) click to toggle source
# File lib/onebox/layout.rb, line 14
def initialize(name, record)
  @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

Public Instance Methods

to_html() click to toggle source
# File lib/onebox/layout.rb, line 28
def to_html
  render(details)
end

Private Instance Methods

details() click to toggle source
# File lib/onebox/layout.rb, line 38
def details
  {
    link: record[:link],
    title: record[:title],
    favicon: record[:favicon],
    domain: record[:domain] || uri.host.to_s.sub(/^www\./, ''),
    article_published_time: record[:article_published_time],
    article_published_time_title: record[:article_published_time_title],
    metadata_1_label: record[:metadata_1_label],
    metadata_1_value: record[:metadata_1_value],
    metadata_2_label: record[:metadata_2_label],
    metadata_2_value: record[:metadata_2_value],
    subname: view.template_name,
    view: view.to_html
  }
end
uri() click to toggle source
# File lib/onebox/layout.rb, line 34
def uri
  @uri ||= URI(::Onebox::Helpers.normalize_url_for_output(record[:link]))
end