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