Class: Rubyword::Writer::Part::Document

Inherits:
Base
  • Object
show all
Includes:
Toc
Defined in:
lib/rubyword/writer/part/document.rb

Constant Summary collapse

DOCUMENT_ATTR =
{
  'xmlns:ve' => "http://schemas.openxmlformats.org/markup-compatibility/2006",
  '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:wp' => "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing",
  'xmlns:w10' => "urn:schemas-microsoft-com:office:word",
  'xmlns:w' => "http://schemas.openxmlformats.org/wordprocessingml/2006/main",
  'xmlns:wne' => "http://schemas.microsoft.com/office/word/2006/wordml"
}

Instance Attribute Summary

Attributes inherited from Base

#rubyword, #section

Instance Method Summary collapse

Methods included from Toc

#write_toc

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Rubyword::Writer::Part::Base

Instance Method Details

#section_write(xml) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rubyword/writer/part/document.rb', line 29

def section_write(xml)
  @object_blocks = []
  sections_count = @rubyword.sections.count
  current_section = 0
  # write TOC
  toc_block = write_toc(@rubyword, xml)
  @object_blocks.push(toc_block) if toc_block
  @rubyword.sections.each do |section|
    current_section = current_section + 1
    # 遍历输出各对象 object 信息
    section.objects.each{|object| @object_blocks << object.write(section, xml)}
    if current_section == sections_count
      @object_blocks << Style::Section.new(section, xml, @rubyword).write
    else
      p_block = xml.send('w:p') {
        xml.send('w:pPr') {
          @object_blocks << Style::Section.new(section, xml, @rubyword).write
        }
      }
      @object_blocks << p_block
    end
  end
  @object_blocks
end

#writeObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/rubyword/writer/part/document.rb', line 18

def write
  builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
    xml.send('w:document', DOCUMENT_ATTR) {
      xml.send('w:body') {
        section_write(xml)
      }
    }
  end
  builder.to_xml
end