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.



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

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

Instance Attribute Details

#contentObject (readonly)

The XML content.



5
6
7
# File 'lib/troy/xml.rb', line 5

def content
  @content
end

#dataObject (readonly)

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



10
11
12
# File 'lib/troy/xml.rb', line 10

def data
  @data
end

Instance Method Details

#contextObject



17
18
19
# File 'lib/troy/xml.rb', line 17

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

#to_xmlObject



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

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

#xmlObject



21
22
23
# File 'lib/troy/xml.rb', line 21

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