Class: Flowcation::Template
- Inherits:
-
Object
- Object
- Flowcation::Template
- Includes:
- Registry, Substitutions
- Defined in:
- lib/flowcation/template.rb
Instance Attribute Summary collapse
-
#layout_name ⇒ Object
readonly
Returns the value of attribute layout_name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #content ⇒ Object
-
#initialize(doc, layout, path, content_for_blocks, substitutions, format) ⇒ Template
constructor
A new instance of Template.
Methods included from Substitutions
Constructor Details
#initialize(doc, layout, path, content_for_blocks, substitutions, format) ⇒ Template
Returns a new instance of Template.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/flowcation/template.rb', line 6 def initialize(doc, layout, path, content_for_blocks, substitutions, format) @doc = doc @path = path @layout_name = layout @substitutions = substitutions @format = format content_for_blocks.each do |name, | register_block Flowcation::Block.new(name, ) end end |
Instance Attribute Details
#layout_name ⇒ Object (readonly)
Returns the value of attribute layout_name.
5 6 7 |
# File 'lib/flowcation/template.rb', line 5 def layout_name @layout_name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/flowcation/template.rb', line 5 def path @path end |
Class Method Details
.from_config(options = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/flowcation/template.rb', line 38 def self.from_config(={}) new \ Nokogiri::HTML(File.new(['file'])).xpath("//body"), ['layout'], ['path'], ['content_for'], ['substitutions'], ['format'] end |
Instance Method Details
#content ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/flowcation/template.rb', line 17 def content doc = @doc.dup substitute(doc) erb = "" blocks.each do |block| block_doc = doc.at_xpath(block.xpath) raise BlockNotFoundException.build(xpath: block.xpath, path: self.path) unless block_doc content = case block.type when 'content' doc.at_xpath(block.xpath).inner_html when 'replace_collection' doc.xpath(block.xpath).to_html end erb << @format. sub("::name::", block.name). sub("::content::", content) end Render.sanitize(erb) end |