Class: Troy::XML
- Inherits:
-
Object
- Object
- Troy::XML
- Defined in:
- lib/troy/xml.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
The XML content.
-
#data ⇒ Object
readonly
The data that must be rendered within the Troy::Context object.
Instance Method Summary collapse
- #context ⇒ Object
-
#initialize(content, data) ⇒ XML
constructor
A new instance of XML.
- #to_xml ⇒ Object
- #xml ⇒ Object
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
#content ⇒ Object (readonly)
The XML content.
5 6 7 |
# File 'lib/troy/xml.rb', line 5 def content @content end |
#data ⇒ Object (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
#context ⇒ Object
17 18 19 |
# File 'lib/troy/xml.rb', line 17 def context @context ||= Context.new(data.merge(xml: xml)).extend(Helpers) end |
#to_xml ⇒ Object
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 |
#xml ⇒ Object
21 22 23 |
# File 'lib/troy/xml.rb', line 21 def xml @xml ||= Builder::XmlMarkup.new(indent: 2) end |