Class: Yuzu::Generators::CategoryFoldersGenerator

Inherits:
Generator show all
Includes:
Helpers
Defined in:
lib/yuzu/generators/category_folders.rb

Instance Attribute Summary

Attributes inherited from Generator

#directive, #name

Instance Method Summary collapse

Methods inherited from Generator

generators, registry

Constructor Details

#initializeCategoryFoldersGenerator

Returns a new instance of CategoryFoldersGenerator.



9
10
11
12
# File 'lib/yuzu/generators/category_folders.rb', line 9

def initialize
  @name = :category_folders
  @directive = "CATEGORYFOLDERS"
end

Instance Method Details

#folder_for_category(category, blog_folder) ⇒ Object



37
38
39
40
41
42
# File 'lib/yuzu/generators/category_folders.rb', line 37

def folder_for_category(category, blog_folder)
  category_folder = GeneratedFolder.new(category.path, blog_folder)
  index_child = index_for_category(category, category_folder, blog_folder)
  category_folder.append_child(index_child)
  category_folder
end

#generate!(website_folder) ⇒ Object



27
28
29
30
31
# File 'lib/yuzu/generators/category_folders.rb', line 27

def generate!(website_folder)
  @all_categories.each do |category|
    generate_folder_for_category!(category, website_folder.blog_folder)
  end
end

#generate_folder_for_category!(category, blog_folder) ⇒ Object



33
34
35
# File 'lib/yuzu/generators/category_folders.rb', line 33

def generate_folder_for_category!(category, blog_folder)
  blog_folder.append_child(folder_for_category(category, blog_folder))
end

#index_for_category(category, parent_folder, blog_folder) ⇒ Object



44
45
46
47
48
49
# File 'lib/yuzu/generators/category_folders.rb', line 44

def index_for_category(category, parent_folder, blog_folder)
  GeneratedIndex.new(
    parent_folder,
    Yuzu::Generators.category_index_template(blog_folder.path.relative, category.name)
  )
end

#should_generate?(website_folder) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/yuzu/generators/category_folders.rb', line 14

def should_generate?(website_folder)
  website_folder.is_blog?
end

#visitor_filterObject



18
19
20
21
22
23
24
25
# File 'lib/yuzu/generators/category_folders.rb', line 18

def visitor_filter
  proc do |c| 
    if c.file?
      @all_categories = c.all_categories
    end
    c.folder?
  end
end