Class: Lookbook::Page
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Entity
#<=>, #id, #label, #lookup_path, #name, #type
Constructor Details
#initialize(file_path) ⇒ Page
Returns a new instance of Page.
8
9
10
11
12
13
14
15
|
# File 'lib/lookbook/entities/page.rb', line 8
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)
@position_prefixes = true
@sections = []
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
57
58
59
|
# File 'lib/lookbook/entities/page.rb', line 57
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
Returns the value of attribute content.
6
7
8
|
# File 'lib/lookbook/entities/page.rb', line 6
def content
@content
end
|
#sections ⇒ Object
Returns the value of attribute sections.
6
7
8
|
# File 'lib/lookbook/entities/page.rb', line 6
def sections
@sections
end
|
Instance Method Details
#add_section(section) ⇒ Object
52
53
54
55
|
# File 'lib/lookbook/entities/page.rb', line 52
def add_section(section)
@sections << section
@sections.sort_by! { |section| [section.position, section.label] }
end
|
#data ⇒ Object
37
38
39
40
41
42
|
# File 'lib/lookbook/entities/page.rb', line 37
def data
return @_data if @_data
config_data = fetch_config(:data, {})
@_data ||= config_data.is_a?(Hash) ? Store.new(config_data) : config_data
end
|
33
34
35
|
# File 'lib/lookbook/entities/page.rb', line 33
def
@_footer ||= fetch_config(:footer, true)
end
|
29
30
31
|
# File 'lib/lookbook/entities/page.rb', line 29
def
@_header ||= fetch_config(:header, true)
end
|
#landing? ⇒ Boolean
21
22
23
|
# File 'lib/lookbook/entities/page.rb', line 21
def landing?
@_landing ||= fetch_config(:landing, false)
end
|
#markdown? ⇒ Boolean
25
26
27
|
# File 'lib/lookbook/entities/page.rb', line 25
def markdown?
@_markdown ||= fetch_config(:markdown) { file_path.to_s.match?(/(.*)\.md\.(.*)$/) }
end
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
61
62
63
|
# File 'lib/lookbook/entities/page.rb', line 61
def respond_to_missing?(method_name, include_private = false)
frontmatter.key?(method_name) || super
end
|
#search_terms ⇒ Object
44
45
46
|
# File 'lib/lookbook/entities/page.rb', line 44
def search_terms
label
end
|
#title ⇒ Object
17
18
19
|
# File 'lib/lookbook/entities/page.rb', line 17
def title
@_title ||= fetch_config(:title, label)
end
|
#url_path ⇒ Object
48
49
50
|
# File 'lib/lookbook/entities/page.rb', line 48
def url_path
lookbook_page_path(path)
end
|