Class: Caracal::Renderers::DocumentRenderer

Inherits:
XmlRenderer
  • Object
show all
Defined in:
lib/caracal/renderers/document_renderer.rb

Instance Attribute Summary

Attributes inherited from XmlRenderer

#document

Instance Method Summary collapse

Methods inherited from XmlRenderer

#initialize, render

Constructor Details

This class inherits a constructor from Caracal::Renderers::XmlRenderer

Instance Method Details

#to_xmlObject

This method produces the xml required for the ‘word/document.xml` sub-document.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/caracal/renderers/document_renderer.rb', line 18

def to_xml
  builder = ::Nokogiri::XML::Builder.with(declaration_xml) do |xml|
    xml.send 'w:document', root_options do
      xml.send 'w:background', { 'w:color' => 'FFFFFF' }
      xml.send 'w:body' do

        #============= CONTENTS ===================================

        document.contents.each do |model|
          method = render_method_for_model(model)
          send(method, xml, model)
        end

        #============= PAGE SETTINGS ==============================

        xml.send 'w:sectPr' do
          if document.page_number_show
            if rel = document.find_relationship('footer1.xml')
              xml.send 'w:footerReference', { 'r:id' => rel.formatted_id, 'w:type' => 'default' }
            end
          end
          xml.send 'w:pgSz', page_size_options
          xml.send 'w:pgMar', page_margin_options
        end

      end
    end
  end
  builder.to_xml(save_options)
end