Class: Mixml::Template::Xml

Inherits:
Base
  • Object
show all
Defined in:
lib/mixml/template/xml.rb

Overview

XML builder based template

Instance Method Summary collapse

Methods inherited from Base

#to_mixml_template

Constructor Details

#initialize(proc) ⇒ Xml

Initialize new XML template

Parameters:

  • proc (lambda)

    Proc to create xml



12
13
14
# File 'lib/mixml/template/xml.rb', line 12

def initialize(proc)
    @proc = proc
end

Instance Method Details

#evaluate(node) ⇒ String

Evaluate the template

Parameters:

  • node (Nokogiri::XML::Node)

    Current node

Returns:

  • (String)

    Template result



20
21
22
23
24
25
# File 'lib/mixml/template/xml.rb', line 20

def evaluate(node)
    builder = Nokogiri::XML::Builder.new do |xml|
        @proc.call(node, xml)
    end
    builder.to_xml
end