Class: Docxtor::RunningElement

Inherits:
Object
  • Object
show all
Defined in:
lib/docxtor/running_element.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, num, contents, options = {}) ⇒ RunningElement

Returns a new instance of RunningElement.



5
6
7
8
9
10
11
# File 'lib/docxtor/running_element.rb', line 5

def initialize type, num, contents, options = {}
  @type = type
  @contents = contents
  @align = options[:align]
  @pages = options[:pages] || :default
  @num = num
end

Instance Attribute Details

#pagesObject

Returns the value of attribute pages.



3
4
5
# File 'lib/docxtor/running_element.rb', line 3

def pages
  @pages
end

#reference_idObject

Returns the value of attribute reference_id.



3
4
5
# File 'lib/docxtor/running_element.rb', line 3

def reference_id
  @reference_id
end

#typeObject

Returns the value of attribute type.



3
4
5
# File 'lib/docxtor/running_element.rb', line 3

def type
  @type
end

Instance Method Details

#contentObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/docxtor/running_element.rb', line 29

def content
  xml = ::Builder::XmlMarkup.new

  xml.instruct! :xml, :version => "1.0", :encoding=>"UTF-8", :standalone => "yes"
  xml.w :ftr, "xmlns:o" => "urn:schemas-microsoft-com:office:office",
  "xmlns:r" => "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
  "xmlns:v" => "urn:schemas-microsoft-com:vml",
  "xmlns:w" => "http://schemas.openxmlformats.org/wordprocessingml/2006/main",
  "xmlns:w10" => "urn:schemas-microsoft-com:office:word",
  "xmlns:wp" => "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" do |xml|

    xml.w :p do |xml|
      xml.w :pPr do |xml|
        xml.w :jc, "w:val" => "#{@align}" if @align
      end
      if @contents == :pagenum
        xml.w :r do |xml|
          xml.w :fldChar, "w:fldCharType" => "begin"
        end
        xml.w :r do |xml|
          xml.w :instrText, "PAGE"
        end
        xml.w :r do |xml|
          xml.w :fldChar, "w:fldCharType" => "separate"
        end
        xml.w :r do |xml|
          xml.w :t, "i"
        end
        xml.w :r do |xml|
          xml.w :fldChar, "w:fldCharType" => "end"
        end
      else
        xml.w :r do |xml|
          xml.w :t, @contents
        end
      end
    end
  end
end

#filenameObject



21
22
23
# File 'lib/docxtor/running_element.rb', line 21

def filename
  "word/#{name}"
end

#nameObject



17
18
19
# File 'lib/docxtor/running_element.rb', line 17

def name
  "#{type}#{@num}.xml"
end

#reference_nameObject



13
14
15
# File 'lib/docxtor/running_element.rb', line 13

def reference_name
  "#{type}Reference"
end

#reference_typeObject



25
26
27
# File 'lib/docxtor/running_element.rb', line 25

def reference_type
  "http://schemas.openxmlformats.org/officeDocument/2006/relationships/#{type}"
end