Class: Henshin::Label
- Inherits:
-
Object
- Object
- Henshin::Label
- Defined in:
- lib/henshin/labels.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#posts ⇒ Object
Returns the value of attribute posts.
-
#site ⇒ Object
Returns the value of attribute site.
Instance Method Summary collapse
- #fake_write_path ⇒ Object
-
#initialize(name, base, site) ⇒ Label
constructor
Creates a new instance of label.
- #inspect ⇒ Object
-
#permalink ⇒ String
Permalink for the label.
-
#to_hash ⇒ Object
Converts the label to a hash.
-
#url ⇒ String
Url for the label.
-
#write ⇒ Object
Writes the label page.
Constructor Details
#initialize(name, base, site) ⇒ Label
Creates a new instance of label
97 98 99 100 101 102 |
# File 'lib/henshin/labels.rb', line 97 def initialize(name, base, site) @name = name @base = base @site = site @posts = [] end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
90 91 92 |
# File 'lib/henshin/labels.rb', line 90 def name @name end |
#posts ⇒ Object
Returns the value of attribute posts.
90 91 92 |
# File 'lib/henshin/labels.rb', line 90 def posts @posts end |
#site ⇒ Object
Returns the value of attribute site.
90 91 92 |
# File 'lib/henshin/labels.rb', line 90 def site @site end |
Instance Method Details
#fake_write_path ⇒ Object
124 125 126 |
# File 'lib/henshin/labels.rb', line 124 def fake_write_path @site.root + self.permalink[1..-1] end |
#inspect ⇒ Object
139 140 141 |
# File 'lib/henshin/labels.rb', line 139 def inspect "#<Label:#{@base}/#{@name}>" end |
#permalink ⇒ String
Returns permalink for the label.
114 115 116 |
# File 'lib/henshin/labels.rb', line 114 def permalink File.join(@site.base, @base, "#{@name.slugify}/index.html") end |
#to_hash ⇒ Object
Converts the label to a hash
105 106 107 108 109 110 111 |
# File 'lib/henshin/labels.rb', line 105 def to_hash hash = { 'name' => @name, 'posts' => @posts.sort.collect {|i| i.to_hash}, 'url' => self.url } end |
#url ⇒ String
Returns url for the label.
119 120 121 |
# File 'lib/henshin/labels.rb', line 119 def url File.join(@site.base, @base, "#{@name.slugify}") end |
#write ⇒ Object
Writes the label page
129 130 131 132 133 134 135 136 137 |
# File 'lib/henshin/labels.rb', line 129 def write payload = {:name => @base, :payload => self.to_hash} page = Gen.new(self.fake_write_path, @site, payload) page.read page.data['layout'] = @site.layouts["#{@base}_page"] page.render page.write end |