Class: OpenXml::Docx::Parts::Document

Inherits:
Part
  • Object
show all
Includes:
RootNamespaces
Defined in:
lib/openxml/docx/parts/document.rb

Constant Summary

Constants included from RootNamespaces

RootNamespaces::POSSIBLE_NAMESPACES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RootNamespaces

included

Constructor Details

#initializeDocument

Returns a new instance of Document.


12
13
14
15
# File 'lib/openxml/docx/parts/document.rb', line 12

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

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children


7
8
9
# File 'lib/openxml/docx/parts/document.rb', line 7

def children
  @children
end

#current_sectionObject (readonly)

Returns the value of attribute current_section


7
8
9
# File 'lib/openxml/docx/parts/document.rb', line 7

def current_section
  @current_section
end

#relationshipsObject (readonly)

Returns the value of attribute relationships


7
8
9
# File 'lib/openxml/docx/parts/document.rb', line 7

def relationships
  @relationships
end

Instance Method Details

#<<(child) ⇒ Object


17
18
19
20
21
22
23
# File 'lib/openxml/docx/parts/document.rb', line 17

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

#backgroundObject


34
35
36
# File 'lib/openxml/docx/parts/document.rb', line 34

def background
  @background ||= OpenXml::Docx::Elements::Background.new
end

#set_section(section) ⇒ Object


25
26
27
28
29
30
31
32
# File 'lib/openxml/docx/parts/document.rb', line 25

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

#to_xmlObject


38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/openxml/docx/parts/document.rb', line 38

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