Class: Lookbook::PageCollection
- Inherits:
-
EntityCollection
- Object
- EntityCollection
- Lookbook::PageCollection
- Includes:
- HierarchicalCollection
- Defined in:
- lib/lookbook/entities/collections/page_collection.rb
Instance Attribute Summary
Attributes inherited from EntityCollection
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from EntityCollection
#add, #each, #find_by_id, #find_by_path, #flat_map, #initialize, #next, #previous
Constructor Details
This class inherits a constructor from Lookbook::EntityCollection
Class Method Details
.entity(file_path) ⇒ Object
26 27 28 |
# File 'lib/lookbook/entities/collections/page_collection.rb', line 26 def self.entity(file_path) File.basename(file_path).match?(%r{\[(.*?\w+)\]}) ? PageSection.new(file_path) : Page.new(file_path) end |
Instance Method Details
#load(page_paths) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/lookbook/entities/collections/page_collection.rb', line 5 def load(page_paths) @entities = [] clear_cache file_paths = page_paths.flat_map do |dir| PathUtils.normalize_paths(Dir["#{dir}/**/*.html.*", "#{dir}/**/*.md.*"].sort) end entities = file_paths.map { |path| PageCollection.entity(path) } pages, sections = entities.partition { |page| page.type == :page } page_dict = pages.index_by(&:lookup_path) sections.each do |section| parent = page_dict[section.lookup_path] section.parent = parent parent.add_section(section) end add(pages) end |