Class: Lookbook::PageEntity

Inherits:
Entity
  • Object
show all
Includes:
LocatableEntity, NavigableEntity
Defined in:
lib/lookbook/entities/page_entity.rb

Overview

Represents a documentation page

Direct Known Subclasses

PageSectionEntity

Instance Attribute Summary collapse

Identity collapse

Frontmatter collapse

Predicates collapse

URLs collapse

Instance Method Summary collapse

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

#contentObject (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

#sectionsObject (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

#dataHash

Merged data hash. Combines ‘data` set in frontmatter with any global default values.

Returns:

  • (Hash)

    The resolved data hash



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_pathString Also known as: url_path

The docs URL path for this page.

Returns:

  • (String)

    URL path



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.

Returns:

  • (Boolean)


87
88
89
# File 'lib/lookbook/entities/page_entity.rb', line 87

def footer?
  @_footer ||= fetch_config(:footer, true)
end

#header?Boolean

Whether the page header will be shown.

Set via the ‘header` frontmatter property.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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_termsObject

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

#titleString

Page title, as defined in frontmatter. Defaults to the page ‘label` if not provided.

Returns:

  • (String)

    The title



31
32
33
# File 'lib/lookbook/entities/page_entity.rb', line 31

def title
  @_title ||= fetch_config(:title, label)
end