Class: Apogee::PageRenderer
- Inherits:
-
Object
- Object
- Apogee::PageRenderer
show all
- Includes:
- BuilderHelpers
- Defined in:
- lib/apogee/page_renderer.rb
Overview
Processes site pages for distribution
Constant Summary
collapse
/\A<!--[^>]*-->/.freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
#css?, #css_paths, #image_paths, #images?, #js?, #js_paths, #layout
Instance Attribute Details
#page_content ⇒ Object
Returns the value of attribute page_content.
13
14
15
|
# File 'lib/apogee/page_renderer.rb', line 13
def page_content
@page_content
end
|
Instance Method Details
#automatic_tokens ⇒ Object
31
32
33
34
35
36
37
38
|
# File 'lib/apogee/page_renderer.rb', line 31
def automatic_tokens
{
'layout' => 'default',
'css_bundle' => css_bundle,
'js_bundle' => js_bundle,
'page_content' => cleaned_page_content
}
end
|
#cleaned_page_content ⇒ Object
66
67
68
|
# File 'lib/apogee/page_renderer.rb', line 66
def cleaned_page_content
page_content.gsub(, '').strip
end
|
#css_bundle ⇒ Object
54
55
56
57
58
|
# File 'lib/apogee/page_renderer.rb', line 54
def css_bundle
return '' unless css?
'<link rel="stylesheet" href="styles.css">'
end
|
#js_bundle ⇒ Object
60
61
62
63
64
|
# File 'lib/apogee/page_renderer.rb', line 60
def js_bundle
return '' unless js?
'<script src="script.js"></script>'
end
|
#layout_content ⇒ Object
23
24
25
|
# File 'lib/apogee/page_renderer.rb', line 23
def layout_content
layout(tokens['layout'])
end
|
#parsed_tokens ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/apogee/page_renderer.rb', line 40
def parsed_tokens
doc = page_content
.match()[0]
.delete_prefix('<!--')
.delete_suffix('-->')
.each_line
.map(&:strip)
.join("\n")
YAML.safe_load(doc)
rescue StandardError
{}
end
|
#render(page_content) ⇒ Object
15
16
17
18
19
20
21
|
# File 'lib/apogee/page_renderer.rb', line 15
def render(page_content)
@page_content = page_content
tokens.inject(layout_content) do |rendered, (name, value)|
rendered.gsub("{{#{name}}}", value)
end
end
|
#tokens ⇒ Object
27
28
29
|
# File 'lib/apogee/page_renderer.rb', line 27
def tokens
automatic_tokens.merge(parsed_tokens)
end
|