Class: Mixml::Template::Text

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

Overview

Ruby string template

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#to_mixml_template

Constructor Details

#initialize(text) ⇒ Text

Initialize a new template

Parameters:

  • text (String)

    Template text

Raises:

  • (ArgumentError)


13
14
15
16
17
# File 'lib/mixml/template/text.rb', line 13

def initialize(text)
    raise(ArgumentError, 'Text must not be nil.') if text.nil?

    @text = '"' << text.gsub('"', '\"') << '"'
end

Instance Attribute Details

#textString (readonly)

Returns Template text.

Returns:



8
9
10
# File 'lib/mixml/template/text.rb', line 8

def text
  @text
end

Instance Method Details

#evaluate(node) ⇒ Object

Evaulate the template using Ruby string interpolation

Parameters:

  • node (Nokogiri::XML::Node)

    Current node



22
23
24
# File 'lib/mixml/template/text.rb', line 22

def evaluate(node)
    eval(@text, binding)
end