Class: Broadway::Post

Inherits:
Object
  • Object
show all
Includes:
Assetable, Configurable, Convertible, Hierarchical, Layoutable, Processable, Publishable, Readable, Resourceful, Sluggable, Sortable, Taggable, Themeable, Comparable
Defined in:
lib/broadway/resources/post.rb

Instance Attribute Summary

Attributes included from Themeable

#template

Attributes included from Layoutable

#layout

Instance Method Summary collapse

Methods included from Themeable

#template_extensions, #theme

Methods included from Publishable

included

Methods included from Hierarchical

included

Methods included from Assetable

included

Methods included from Taggable

included

Methods included from Sortable

included

Methods included from Sluggable

included

Methods included from Configurable

included

Methods included from Readable

included

Methods included from Resourceful

included

Methods included from Convertible

included

Methods included from Processable

included

Instance Method Details

#bodyObject



46
47
48
# File 'lib/broadway/resources/post.rb', line 46

def body
  read
end

#descriptionObject



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/broadway/resources/post.rb', line 50

def description
  unless @description
    if data["description"]
      @description = data["description"]
    else
      @description = "" # read
    end
  end

  @description
end

#formatObject



39
40
41
# File 'lib/broadway/resources/post.rb', line 39

def format
  extension
end


87
88
89
# File 'lib/broadway/resources/post.rb', line 87

def gallery
  data["gallery"] || nil
end


91
92
93
# File 'lib/broadway/resources/post.rb', line 91

def menu_title
  data["menu_title"] || title
end

#parent_pathObject



99
100
101
# File 'lib/broadway/resources/post.rb', line 99

def parent_path
  ("/" + categories.join("/")).squeeze("/")
end

#self_and_siblingsObject



62
63
64
65
66
67
68
# File 'lib/broadway/resources/post.rb', line 62

def self_and_siblings
  if parent
    parent.children.blank? ? nil : parent.children
  else
    nil
  end
end

#sluggifyObject



19
20
21
22
23
24
25
26
27
# File 'lib/broadway/resources/post.rb', line 19

def sluggify
  {
    "year"       => "",# date ? date.strftime("%Y") : "",
    "month"      => "",# date ? date.strftime("%m") : "",
    "day"        => "",# date ? date.strftime("%d") : "",
    "title"      => kind == "page" ? "" : slug.value,
    "categories" => categories.join('/') # page is "categories[0..-2].join('/')"
  }
end


70
71
72
73
74
75
# File 'lib/broadway/resources/post.rb', line 70

def submenu
  return nil if data["submenu"].blank?
  data["submenu"].map do |path|
    site.find_post_by_path(path)
  end.compact
end

#subpagesObject



77
78
79
80
81
82
83
84
85
# File 'lib/broadway/resources/post.rb', line 77

def subpages
  (self_and_siblings || submenu || children).sort do |a, b|
    if a.data["position"] && b.data["position"]
      a.data["position"].to_i <=> b.data["position"]
    else
      a <=> b
    end
  end
end

#subtitleObject



95
96
97
# File 'lib/broadway/resources/post.rb', line 95

def subtitle
  data["subtitle"] || nil
end

#to_hashObject



29
30
31
32
33
34
35
36
37
# File 'lib/broadway/resources/post.rb', line 29

def to_hash
  { "title"      => self.title,
    "url"        => self.url,
    "date"       => self.date,
    "id"         => self.id,
    "categories" => self.categories,
    "tags"       => self.tags,
    "content"    => self.content }.deep_merge(self.data)
end

#updated_atObject Also known as: created_at



42
43
44
# File 'lib/broadway/resources/post.rb', line 42

def updated_at
  date
end