Class: Mixml::Template::Expression

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

Overview

Eruby based template

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#to_mixml_template

Constructor Details

#initialize(text) ⇒ Expression

Initialize a new template

Parameters:

  • text (String)

    Template text



15
16
17
# File 'lib/mixml/template/expression.rb', line 15

def initialize(text)
    @expression = Erubis::Eruby.new(text, :pattern => '{ }')
end

Instance Attribute Details

#expressionErubis::Eruby (readonly)

Returns Template expression.

Returns:

  • (Erubis::Eruby)

    Template expression



10
11
12
# File 'lib/mixml/template/expression.rb', line 10

def expression
  @expression
end

Instance Method Details

#evaluate(node) ⇒ String

Evaluate the template

Parameters:

  • node (Nokogiri::XML::Node)

    Current node

Returns:

  • (String)

    Template result



23
24
25
26
# File 'lib/mixml/template/expression.rb', line 23

def evaluate(node)
    context = {:node => node}
    @expression.result(context)
end