Class: Flowcation::Partial

Inherits:
Object
  • Object
show all
Includes:
Callbacks, Substitutions
Defined in:
lib/flowcation/partial.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Substitutions

#substitute

Constructor Details

#initialize(doc, path, substitutions) ⇒ Partial

Returns a new instance of Partial.



5
6
7
8
9
# File 'lib/flowcation/partial.rb', line 5

def initialize(doc, path, substitutions)
  @doc = doc
  @path = path
  @substitutions = substitutions || []
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



4
5
6
# File 'lib/flowcation/partial.rb', line 4

def path
  @path
end

Class Method Details

.from_config(options = {}) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/flowcation/partial.rb', line 17

def self.from_config(options={})
  doc = Nokogiri::HTML(File.new(options['file'])).xpath("//body").xpath(options['xpath'])
  doc = doc[0].children if options['type'] == 'content'
  partial = Flowcation::Partial.new \
    doc,
    options['path'],
    options['substitutions']
end

Instance Method Details

#contentObject



11
12
13
14
15
# File 'lib/flowcation/partial.rb', line 11

def content
  doc = @doc.dup
  substitute(doc)
  Render.sanitize(doc.to_html(encoding: 'UTF-8'))
end