Class: Henshin::Labels
- Inherits:
-
Array
- Object
- Array
- Henshin::Labels
- Defined in:
- lib/henshin/labels.rb
Overview
This is basically a front for tags and categories, because they are so similar it makes sense to condense them into one class!
Instance Attribute Summary collapse
-
#base ⇒ Object
Returns the value of attribute base.
-
#site ⇒ Object
Returns the value of attribute site.
Instance Method Summary collapse
-
#<<(post) ⇒ Object
Adds the given post to the correct category object in the array or creates the category and adds the post to that.
-
#fake_write_path ⇒ Pathname
Need a fake path where the file would have been so as to trick the gen into constructing the correct paths.
-
#initialize(base, site) ⇒ Labels
constructor
Creates a new instance of labels.
-
#permalink ⇒ String
Permalink for label index.
-
#to_hash ⇒ Object
Converts the labels to a hash for use in a layout parser.
-
#url ⇒ String
Base url for label.
-
#write ⇒ Object
Writes the category index, then writes the individual category pages.
Constructor Details
#initialize(base, site) ⇒ Labels
Creates a new instance of labels
14 15 16 17 |
# File 'lib/henshin/labels.rb', line 14 def initialize(base, site) @base = base @site = site end |
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base.
8 9 10 |
# File 'lib/henshin/labels.rb', line 8 def base @base end |
#site ⇒ Object
Returns the value of attribute site.
8 9 10 |
# File 'lib/henshin/labels.rb', line 8 def site @site end |
Instance Method Details
#<<(post) ⇒ Object
Make it a bit more abstract, actually hard coding stuff in will lead to problems!
Adds the given post to the correct category object in the array or creates the category and adds the post to that
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/henshin/labels.rb', line 27 def <<(post) k = nil if base == 'tag' k = post.data['tags'] elsif base == 'category' k = [post.data['category']] end k.each do |j| unless self.map{|i| i.name}.include?(j) super Henshin::Label.new(j, @base, @site) end i = self.find_index {|i| i.name == j} self[i].posts << post end end |
#fake_write_path ⇒ Pathname
Need a fake path where the file would have been so as to trick the gen into constructing the correct paths
67 68 69 |
# File 'lib/henshin/labels.rb', line 67 def fake_write_path @site.root + self.permalink[1..-1] end |
#permalink ⇒ String
Returns permalink for label index.
54 55 56 |
# File 'lib/henshin/labels.rb', line 54 def permalink File.join(@site.base, @base, "index.html") end |
#to_hash ⇒ Object
Converts the labels to a hash for use in a layout parser
45 46 47 48 49 50 51 |
# File 'lib/henshin/labels.rb', line 45 def to_hash r = [] self.each do |i| r << i.to_hash end r end |
#url ⇒ String
Returns base url for label.
59 60 61 |
# File 'lib/henshin/labels.rb', line 59 def url File.join(@site.base, @base) end |
#write ⇒ Object
Writes the category index, then writes the individual category pages
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/henshin/labels.rb', line 73 def write if @site.layouts["#{@base}_index"] page = Gen.new(self.fake_write_path, @site) page.read page.data['layout'] = @site.layouts["#{@base}_index"] page.render page.write end if @site.layouts["#{@base}_page"] self.each {|label| label.write } end end |