class Flowcation::Template

Attributes

layout_name[R]
path[R]

Public Class Methods

from_config(options={}) click to toggle source
# File lib/flowcation/template.rb, line 38
def self.from_config(options={})
  new \
    Nokogiri::HTML(File.new(options['file'])).xpath("//body"), 
    options['layout'], 
    options['path'], 
    options['content_for'], 
    options['substitutions'], 
    options['format']
end
new(doc, layout, path, content_for_blocks, substitutions, format) click to toggle source
# 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, options|
    register_block Flowcation::Block.new(name, options)
  end
end

Public Instance Methods

content() click to toggle source
# 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