Class: Troy::XML

Inherits:
Object
  • Object
show all
Defined in:
lib/troy/xml.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content, data) ⇒ XML

Returns a new instance of XML.



14
15
16
17
# File 'lib/troy/xml.rb', line 14

def initialize(content, data)
  @content = content
  @data = data
end

Instance Attribute Details

#contentObject (readonly)

The XML content.



7
8
9
# File 'lib/troy/xml.rb', line 7

def content
  @content
end

#dataObject (readonly)

The data that must be rendered within the Troy::Context object.



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

def data
  @data
end

Instance Method Details

#contextObject



19
20
21
# File 'lib/troy/xml.rb', line 19

def context
  @context ||= Context.new(data.merge(xml: xml)).extend(Helpers)
end

#to_xmlObject



27
28
29
30
31
32
33
# File 'lib/troy/xml.rb', line 27

def to_xml
  @to_xml ||= begin
    xml.instruct!
    context.instance_eval(content)
    xml.target!
  end
end

#xmlObject



23
24
25
# File 'lib/troy/xml.rb', line 23

def xml
  @xml ||= Builder::XmlMarkup.new(indent: 2)
end