Class: Zine::Page::FormattedData

Inherits:
Object
  • Object
show all
Includes:
ERB::Util
Defined in:
lib/zine/page.rb

Overview

the meta data, passed formatted to the template

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(front_matter, site_opt) ⇒ FormattedData

Returns a new instance of FormattedData.



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/zine/page.rb', line 27

def initialize(front_matter, site_opt)
  @page = { date_rfc3339: front_matter['date'],
            date_us: parse_date(front_matter['date']),
            github_name: site_opt['options']['github_name'],
            num_items_on_home: site_opt['options']['num_items_on_home'],
            site_author: site_opt['options']['site_author'],
            site_description: site_opt['options']['site_description'],
            site_name: site_opt['options']['site_name'],
            site_URL: site_opt['options']['site_URL'],
            tags: slugify_tags(front_matter['tags']),
            title: html_escape(front_matter['title']),
            twitter_name: site_opt['options']['twitter_name'] }
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



20
21
22
# File 'lib/zine/page.rb', line 20

def data
  @data
end

Returns the value of attribute footer_partial.



21
22
23
# File 'lib/zine/page.rb', line 21

def footer_partial
  @footer_partial
end

#header_partialObject

Returns the value of attribute header_partial.



22
23
24
# File 'lib/zine/page.rb', line 22

def header_partial
  @header_partial
end

#htmlObject

Returns the value of attribute html.



23
24
25
# File 'lib/zine/page.rb', line 23

def html
  @html
end

#pageObject (readonly)

Returns the value of attribute page.



24
25
26
# File 'lib/zine/page.rb', line 24

def page
  @page
end

#uriObject

Returns the value of attribute uri.



25
26
27
# File 'lib/zine/page.rb', line 25

def uri
  @uri
end

Instance Method Details

#parse_date(front_matter_date) ⇒ Object



41
42
43
44
45
# File 'lib/zine/page.rb', line 41

def parse_date(front_matter_date)
  DateTime.rfc3339(front_matter_date).strftime('%B %-d, %Y')
rescue
  ''
end

#public_bindingObject



47
48
49
# File 'lib/zine/page.rb', line 47

def public_binding
  binding
end

#slugify_tags(tags) ⇒ Object



51
52
53
54
# File 'lib/zine/page.rb', line 51

def slugify_tags(tags)
  return unless tags && tags.any?
  tags.map { |tag| { name: tag, tag_slug: Page.slug(tag) } }
end