Class: Zine::Tag

Inherits:
Object
  • Object
show all
Defined in:
lib/zine/tag.rb

Overview

Posts’ tags

Instance Method Summary collapse

Constructor Details

#initialize(tags_by_post, tag_templates, tag_index_templates, options) ⇒ Tag

Returns a new instance of Tag.



8
9
10
11
12
13
14
15
# File 'lib/zine/tag.rb', line 8

def initialize(tags_by_post, tag_templates, tag_index_templates, options)
  @options = options
  @posts_by_tag = sort_tags tags_by_post
  @templates = { tag: tag_templates, tag_index: tag_index_templates }
  @tag_dir = File.join @options['directories']['build'], 'tags'
  FileUtils.remove_dir @tag_dir, force: true
  FileUtils.mkdir_p @tag_dir
end

Instance Method Details

#write_tagsObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/zine/tag.rb', line 17

def write_tags
  @posts_by_tag.each do |tag_name, struct_array|
    sorted_array = sort_tags_by_date struct_array
    data = { name: tag_name, title: "Tags: #{tag_name}",
             post_array: sorted_array, build_dir: @tag_dir }
    tag_page = Zine::DataPage.new(data, @templates[:tag], @options)
    tag_page.write
  end
  write_tag_index
end