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.
14 15 16 17 |
# File 'lib/troy/xml.rb', line 14 def initialize(content, data) @content = content @data = data end |
Instance Attribute Details
#content ⇒ Object (readonly)
The XML content.
7 8 9 |
# File 'lib/troy/xml.rb', line 7 def content @content end |
#data ⇒ Object (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
#context ⇒ Object
19 20 21 |
# File 'lib/troy/xml.rb', line 19 def context @context ||= Context.new(data.merge(xml: xml)).extend(Helpers) end |
#to_xml ⇒ Object
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 |
#xml ⇒ Object
23 24 25 |
# File 'lib/troy/xml.rb', line 23 def xml @xml ||= Builder::XmlMarkup.new(indent: 2) end |