Class: Lookbook::PageEntity
- Includes:
- LocatableEntity, NavigableEntity
- Defined in:
- lib/lookbook/entities/page_entity.rb
Overview
Represents a documentation page
Direct Known Subclasses
Instance Attribute Summary collapse
- #content ⇒ Object readonly private
- #sections ⇒ Object readonly private
Identity collapse
-
#title ⇒ String
Page title, as defined in frontmatter.
Frontmatter collapse
-
#data ⇒ Hash
Merged data hash.
Predicates collapse
-
#footer? ⇒ Boolean
Whether the page footer will be shown.
-
#header? ⇒ Boolean
Whether the page header will be shown.
-
#landing? ⇒ Boolean
Whether the page is the default landing page.
-
#markdown? ⇒ Boolean
Whether the page content should be rendered with the Markdown renderer.
URLs collapse
-
#docs_path ⇒ String
(also: #url_path)
The docs URL path for this page.
Instance Method Summary collapse
- #add_section(section) ⇒ Object private
-
#initialize(file_path) ⇒ PageEntity
constructor
private
A new instance of PageEntity.
- #method_missing(method_name, *args, &block) ⇒ Object private
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean private
- #search_terms ⇒ Object private
Methods inherited from Entity
#<=>, #id, #label, #lookup_path, #name, #type
Constructor Details
#initialize(file_path) ⇒ PageEntity
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of PageEntity.
16 17 18 19 20 21 22 23 |
# File 'lib/lookbook/entities/page_entity.rb', line 16 def initialize(file_path) @file_path = Pathname(file_path) @base_directories = Engine.page_paths @lookup_path = PathUtils.to_lookup_path(relative_file_path) @frontmatter, @content = FrontmatterExtractor.call(file_contents) @priority_prefixes = true @sections = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
118 119 120 |
# File 'lib/lookbook/entities/page_entity.rb', line 118 def method_missing(method_name, *args, &block) method_name.to_s.end_with?("=") ? super : frontmatter.fetch(method_name, nil) end |
Instance Attribute Details
#content ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
10 11 12 |
# File 'lib/lookbook/entities/page_entity.rb', line 10 def content @content end |
#sections ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
13 14 15 |
# File 'lib/lookbook/entities/page_entity.rb', line 13 def sections @sections end |
Instance Method Details
#add_section(section) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
112 113 114 115 |
# File 'lib/lookbook/entities/page_entity.rb', line 112 def add_section(section) @sections << section @sections.sort_by! { |section| [section.priority, section.label] } end |
#data ⇒ Hash
Merged data hash. Combines ‘data` set in frontmatter with any global default values.
43 44 45 46 47 48 |
# File 'lib/lookbook/entities/page_entity.rb', line 43 def data return @_data if @_data config_data = fetch_config(:data, {}) @_data ||= config_data.is_a?(Hash) ? Store.new(config_data) : config_data end |
#docs_path ⇒ String Also known as: url_path
The docs URL path for this page.
98 99 100 |
# File 'lib/lookbook/entities/page_entity.rb', line 98 def docs_path lookbook_page_path(lookup_path) end |
#footer? ⇒ Boolean
Whether the page footer will be shown.
Set via the ‘footer` frontmatter property.
87 88 89 |
# File 'lib/lookbook/entities/page_entity.rb', line 87 def @_footer ||= fetch_config(:footer, true) end |
#header? ⇒ Boolean
Whether the page header will be shown.
Set via the ‘header` frontmatter property.
78 79 80 |
# File 'lib/lookbook/entities/page_entity.rb', line 78 def header? @_header ||= fetch_config(:header, true) end |
#landing? ⇒ Boolean
Whether the page is the default landing page.
Set via the ‘landing` frontmatter property.
59 60 61 |
# File 'lib/lookbook/entities/page_entity.rb', line 59 def landing? @_landing ||= fetch_config(:landing, false) end |
#markdown? ⇒ Boolean
Whether the page content should be rendered with the Markdown renderer.
Set via the ‘markdown` frontmatter property.
69 70 71 |
# File 'lib/lookbook/entities/page_entity.rb', line 69 def markdown? @_markdown ||= fetch_config(:markdown) { file_path.to_s.match?(/(.*)\.md\.(.*)$/) } end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
123 124 125 |
# File 'lib/lookbook/entities/page_entity.rb', line 123 def respond_to_missing?(method_name, include_private = false) frontmatter.key?(method_name) || super end |
#search_terms ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
107 108 109 |
# File 'lib/lookbook/entities/page_entity.rb', line 107 def search_terms lookup_path.split("/") << label end |
#title ⇒ String
Page title, as defined in frontmatter. Defaults to the page ‘label` if not provided.
31 32 33 |
# File 'lib/lookbook/entities/page_entity.rb', line 31 def title @_title ||= fetch_config(:title, label) end |