Class: Henshin::Label

Inherits:
Object
  • Object
show all
Defined in:
lib/henshin/labels.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, base, site) ⇒ Label

Creates a new instance of label

Parameters:

  • name (String)

    of the label

  • base (String)

    of the url for the label (see Labels#initialize)

  • site (Site)

    that the label belongs to



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

#nameObject

Returns the value of attribute name.



90
91
92
# File 'lib/henshin/labels.rb', line 90

def name
  @name
end

#postsObject

Returns the value of attribute posts.



90
91
92
# File 'lib/henshin/labels.rb', line 90

def posts
  @posts
end

#siteObject

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_pathObject



124
125
126
# File 'lib/henshin/labels.rb', line 124

def fake_write_path
  @site.root + self.permalink[1..-1]
end

#inspectObject



139
140
141
# File 'lib/henshin/labels.rb', line 139

def inspect
  "#<Label:#{@base}/#{@name}>"
end

Returns permalink for the label.

Returns:

  • (String)

    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_hashObject

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

#urlString

Returns url for the label.

Returns:

  • (String)

    url for the label



119
120
121
# File 'lib/henshin/labels.rb', line 119

def url
  File.join(@site.base, @base, "#{@name.slugify}")
end

#writeObject

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