class Caracal::Renderers::XmlRenderer

Attributes

document[R]

Public Class Methods

new(doc) click to toggle source

This method instantiates a new verison of this renderer.

# File lib/caracal/renderers/xml_renderer.rb, line 34
def initialize(doc)
  unless doc.is_a?(Caracal::Document) or doc.is_a?(Caracal::Header)
    raise NoDocumentError, 'renderers must receive a reference to a valid Caracal document object.'
  end

  @document = doc
end
render(doc) click to toggle source

This method produces xml output for the given document according to the rules of this renderer object.

# File lib/caracal/renderers/xml_renderer.rb, line 22
def self.render(doc)
  renderer = new(doc)
  renderer.to_xml
end

Public Instance Methods

to_xml() click to toggle source

This method converts data in the specified document to XML. A concrete implementation must be provided by the subclass.

# File lib/caracal/renderers/xml_renderer.rb, line 45
def to_xml
  raise NotImplementedError, 'renderers must implement the method :to_xml.'
end

Private Instance Methods

declaration_xml() click to toggle source

This method returns a Nokogiri::XML object that contains the specific declaration we want.

# File lib/caracal/renderers/xml_renderer.rb, line 58
def declaration_xml
  ::Nokogiri::XML('<?xml version = "1.0" encoding = "UTF-8" standalone ="yes"?>')
end
paragraph_options() click to toggle source

This method returns a commonly used set of attributes for paragraph nodes.

# File lib/caracal/renderers/xml_renderer.rb, line 64
def paragraph_options
  { 'w:rsidP' => '00000000', 'w:rsidRDefault' => '00000000' }.merge(run_options)
end
run_options() click to toggle source

This method returns a commonly used set of attributes for text run nodes.

# File lib/caracal/renderers/xml_renderer.rb, line 70
def run_options
  { 'w:rsidR' => '00000000', 'w:rsidRPr' => '00000000', 'w:rsidDel' => '00000000' }
end
save_options() click to toggle source

These save options force Nokogiri to remove indentation and line feeds from the output.

# File lib/caracal/renderers/xml_renderer.rb, line 77
def save_options
  { save_with: Nokogiri::XML::Node::SaveOptions::AS_XML }
end