Class: Category

Inherits:
Zarchitect show all
Defined in:
lib/zarchitect/category.rb

Constant Summary

Constants inherited from Zarchitect

Zarchitect::ASSETDIR, Zarchitect::ASSETSDIR, Zarchitect::BUILDIR, Zarchitect::CONFIGDIR, Zarchitect::DEBUGSDIR, Zarchitect::DRAFTDIR, Zarchitect::FILEDIR, Zarchitect::FILESDIR, Zarchitect::HTMLDIR, Zarchitect::LAYOUTDIR, Zarchitect::NODEDIR, Zarchitect::SHARESDIR, Zarchitect::VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Zarchitect

#main, #rss

Constructor Details

#initialize(key, name, section) ⇒ Category

Returns a new instance of Category.



4
5
6
7
8
9
10
11
# File 'lib/zarchitect/category.rb', line 4

def initialize(key, name, section)
  @key = key
  @name = name
  @section = section
  @url  = "/#{@section.key}/#{@key}/index.html"

  create_dir
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



2
3
4
# File 'lib/zarchitect/category.rb', line 2

def index
  @index
end

#keyObject (readonly)

Returns the value of attribute key.



2
3
4
# File 'lib/zarchitect/category.rb', line 2

def key
  @key
end

#nameObject (readonly)

Returns the value of attribute name.



2
3
4
# File 'lib/zarchitect/category.rb', line 2

def name
  @name
end

#sectionObject (readonly)

Returns the value of attribute section.



2
3
4
# File 'lib/zarchitect/category.rb', line 2

def section
  @section
end

#tagsObject (readonly)

Returns the value of attribute tags.



2
3
4
# File 'lib/zarchitect/category.rb', line 2

def tags
  @tags
end

#urlObject (readonly)

Returns the value of attribute url.



2
3
4
# File 'lib/zarchitect/category.rb', line 2

def url
  @url
end

Instance Method Details

#build_htmlObject



13
14
15
16
17
18
19
20
# File 'lib/zarchitect/category.rb', line 13

def build_html
  if @tags
    @tags.each do |t|
      t.build_html
    end
  end
  @index.build_html
end

#fetch_tagsObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/zarchitect/category.rb', line 31

def fetch_tags
  # after fetch_pages is implemented
  ar = Array.new
  posts.each do |p|
    if p.conf.has_option?("tags")
      p.conf.tags.each { |t| ar.push t }
    end
  end
  ar.sort!.uniq!
  if ar.count == 0
    @tags = nil
  else
    @tags = Array.new
    ar.each { |v| @tags.push Tag.new(v, self) }
  end
end

#postsObject



48
49
50
# File 'lib/zarchitect/category.rb', line 48

def posts
  @section.posts.select { |p| p.category == self }
end

#setup_indexObject



52
53
54
# File 'lib/zarchitect/category.rb', line 52

def setup_index
  @index = Index.new(self)
end

#write_htmlObject



22
23
24
25
26
27
28
29
# File 'lib/zarchitect/category.rb', line 22

def write_html
  if @tags
    @tags.each do |t|
      t.write_html
    end
  end
  @index.write_html
end