Sha256: 3b572f41c26ed91a295e36a943e7027e10bbd9482ab01e55583fa5a3ddc8cee3

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

module OpenXml
  module Docx
    module Parts
      class Document < OpenXml::Part
        include RootNamespaces

        attr_reader :children, :current_section, :relationships

        use_namespaces :wpc, :mo, :mv, :o, :r, :m, :v, :wp14, :wp, :w10, :w14, :wpg, :wpi, :wne, :wps, :w, :mc, :a, :a14, :pic
        can_ignore :w14, :wp14, :a14

        def initialize
          @children = []
          @relationships = OpenXml::Parts::Rels.new
        end

        def <<(child)
          if child.is_a?(OpenXml::Docx::Section)
            set_section(child)
          else
            children << child
          end
        end

        def set_section(section)
          if current_section.nil?
            @current_section = section
          else
            children.last.section_properties = current_section
            @current_section = section
          end
        end

        def to_xml
          build_xml do |xml|
            xml.document(root_namespaces) {
              xml.parent.namespace = :w
              xml["w"].body {
                children.each { |child| child.to_xml(xml) }
                current_section.to_xml(xml) unless current_section.nil?
              }
            }
          end
        end

      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
openxml-docx-0.10.1 lib/openxml/docx/parts/document.rb