Class: Aardi::Template
- Inherits:
-
Object
- Object
- Aardi::Template
- Defined in:
- lib/aardi/template.rb
Overview
:reek:DataClump
Constant Summary collapse
- PLACEHOLDER_MAIN =
'__PLACEHOLDER_MAIN__'- PLACEHOLDER_TITLE =
'__PLACEHOLDER_TITLE__'- PLACEHOLDER_DESCRIPTION =
'__PLACEHOLDER_DESCRIPTION__'
Instance Method Summary collapse
-
#initialize(path) ⇒ Template
constructor
A new instance of Template.
- #render(src) ⇒ Object
Constructor Details
#initialize(path) ⇒ Template
Returns a new instance of Template.
10 11 12 13 14 15 16 17 |
# File 'lib/aardi/template.rb', line 10 def initialize(path) @path = path dom = Nokogiri::HTML5.parse(File.read(path).strip) required(dom, 'main').add_child(PLACEHOLDER_MAIN) required(dom, 'title').content += PLACEHOLDER_TITLE update_description_if_present(dom.at_css('meta[name="description"]')) @compiled = dom.to_html.strip end |
Instance Method Details
#render(src) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/aardi/template.rb', line 19 def render(src) result = @compiled.dup result.sub!(PLACEHOLDER_MAIN, Aardi.renderer.markup(src.content)) result.sub!(PLACEHOLDER_TITLE, " #{text_escape(src.title)}") result.sub!(PLACEHOLDER_DESCRIPTION, description_value(src)) if @default_description result end |