Sha256: 132d67ac691c48439561cffc23bf4926bb7e150b701f01b3e1f341b74d504ba6

Contents?: true

Size: 614 Bytes

Versions: 4

Compression:

Stored size: 614 Bytes

Contents

# frozen_string_literal: true

module Troy
  class XML
    # The XML content.
    #
    attr_reader :content

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

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

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

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

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
troy-0.0.39 lib/troy/xml.rb
troy-0.0.38 lib/troy/xml.rb
troy-0.0.37 lib/troy/xml.rb
troy-0.0.36 lib/troy/xml.rb