Sha256: 6add7b050628aec3e702c655b9b035cd7b78ce7143b1f11b7ccf93cd40a75e3e

Contents?: true

Size: 2 KB

Versions: 3

Compression:

Stored size: 2 KB

Contents

module Rocx
  module Parts
    class Document < BasePart
      attr_reader :children

      def initialize
        @children = []
      end

      def <<(child)
        children << child
      end

      def to_xml
        build_xml do |xml|
          xml.document(root_namespaces) {
            xml.parent.namespace = xml.parent.namespace_definitions.find { |ns| ns.prefix == 'w' }
            xml['w'].body {
              children.each { |child| child.to_xml(xml) }
            }
          }
        end
      end

    private

      def root_namespaces
        { "xmlns:wpc" => 'http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas',
          "xmlns:mo" => 'http://schemas.microsoft.com/office/mac/office/2008/main',
          "xmlns:mv" => 'urn:schemas-microsoft-com:mac:vml',
          "xmlns:o" => 'urn:schemas-microsoft-com:office:office',
          "xmlns:r" => 'http://schemas.openxmlformats.org/officeDocument/2006/relationships',
          "xmlns:m" => 'http://schemas.openxmlformats.org/officeDocument/2006/math',
          "xmlns:v" => 'urn:schemas-microsoft-com:vml',
          "xmlns:wp14" => 'http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing',
          "xmlns:wp" => 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing',
          "xmlns:w10" => 'urn:schemas-microsoft-com:office:word',
          "xmlns:w14" => 'http://schemas.microsoft.com/office/word/2010/wordml',
          "xmlns:wpg" => 'http://schemas.microsoft.com/office/word/2010/wordprocessingGroup',
          "xmlns:wpi" => 'http://schemas.microsoft.com/office/word/2010/wordprocessingInk',
          "xmlns:wne" => 'http://schemas.microsoft.com/office/word/2006/wordml',
          "xmlns:wps" => 'http://schemas.microsoft.com/office/word/2010/wordprocessingShape',
          "xmlns:w" => "http://schemas.openxmlformats.org/wordprocessingml/2006/main",
          "xmlns:mc" => "http://schemas.openxmlformats.org/markup-compatibility/2006",
          "mc:Ignorable" => "w14 wp14" }
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rocx-0.6.0 lib/rocx/parts/document.rb
rocx-0.5.8 lib/rocx/parts/document.rb
rocx-0.5.7 lib/rocx/parts/document.rb