class Docxtor::Document::TableOfContents

Constants

PARAGRAPH_STYLE
STYLE

Public Instance Methods

after_initialize(text) click to toggle source
# File lib/docxtor/document/table_of_contents.rb, line 7
def after_initialize(text)
  create_params({:style => STYLE})
  @text = text
end
render(xml) click to toggle source

TODO: Add support for extended styling & properties

Calls superclass method Docxtor::Document::Element#render
# File lib/docxtor/document/table_of_contents.rb, line 14
def render(xml)
  super

  xml.w :sdt, "xmlns:w" => "http://schemas.openxmlformats.org/wordprocessingml/2006/main" do

    write_properties

    xml.w :sdtContent do

      write_heading

      xml.w :p do
        xml.w :pPr do
          xml.w :pStyle, "w:val" => PARAGRAPH_STYLE
          xml.w :tabs do
            xml.w :tab, "w:val" => "right", "w:leader" => "dot", "w:pos" => 9350
          end
          xml.w :rPr do
            xml.w :noProof
          end
        end
        xml.w :r do
          xml.w :fldChar, "w:fldCharType" => "begin", "w:dirty" => true
        end

        write_instruct

        xml.w :r do
          xml.w :fldChar, "w:fldCharType" => "separate"
        end
      end

      xml.w :p do
        xml.w :r do
          # xml.w :rPr do
          #   xml.w :b
          #   xml.w :bCs
          #   xml.w :noProof
          # end
          xml.w :fldChar, "w:fldCharType" => "end"
        end
      end

    end
  end
end

Private Instance Methods

write_heading() click to toggle source
# File lib/docxtor/document/table_of_contents.rb, line 72
def write_heading
  xml.w :p do
    xml.w :pPr do
      xml.w :pStyle, "w:val" => @params[:style]
    end
    xml.w :r do
      xml.w :t do
        xml.text! @text
      end
    end
  end
end
write_instruct() click to toggle source
# File lib/docxtor/document/table_of_contents.rb, line 85
def write_instruct
  xml.w :r do
    xml.w :instrText, "xml:space" => "preserve" do
      xml.text! " TOC \\o '1-3' \\h \\z \\u "
    end
  end
end
write_properties() click to toggle source
# File lib/docxtor/document/table_of_contents.rb, line 63
def write_properties
  xml.w :sdtPr do
    xml.w :docPartObj do
      xml.w :docPartGallery, "w:val" => "Table of Contents"
      xml.w :docPartUnique
    end
  end
end