Class: Docxi::Word::Headers::Header

Inherits:
Object
  • Object
show all
Defined in:
lib/docxi/word/headers/header.rb

Defined Under Namespace

Classes: Image

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Header

Returns a new instance of Header.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/docxi/word/headers/header.rb', line 9

def initialize(options={})
  @options = options
  @content = []
  @relationships = []

  if block_given?
    yield self
  else

  end
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



8
9
10
# File 'lib/docxi/word/headers/header.rb', line 8

def content
  @content
end

#idObject

Returns the value of attribute id.



8
9
10
# File 'lib/docxi/word/headers/header.rb', line 8

def id
  @id
end

#optionsObject

Returns the value of attribute options.



8
9
10
# File 'lib/docxi/word/headers/header.rb', line 8

def options
  @options
end

#relationships=(value) ⇒ Object

Sets the attribute relationships

Parameters:

  • value

    the value to set the attribute relationships to.



8
9
10
# File 'lib/docxi/word/headers/header.rb', line 8

def relationships=(value)
  @relationships = value
end

#sequenceObject

Returns the value of attribute sequence.



8
9
10
# File 'lib/docxi/word/headers/header.rb', line 8

def sequence
  @sequence
end

Instance Method Details

#br(options = {}) ⇒ Object



61
62
63
64
65
# File 'lib/docxi/word/headers/header.rb', line 61

def br(options={})
  br = Docxi::Word::Contents::Break.new(options)
  @content << br
  br
end

#content_typeObject



21
22
23
# File 'lib/docxi/word/headers/header.rb', line 21

def content_type
  "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header"
end

#image(image, options = {}) ⇒ Object



39
40
41
42
43
44
# File 'lib/docxi/word/headers/header.rb', line 39

def image(image, options={})
  img = Image.new(image, options)
  @content << img
  @relationships << image
  img
end

#page_numbersObject



55
56
57
58
59
# File 'lib/docxi/word/headers/header.rb', line 55

def page_numbers
  numbers = PageNumbers.new
  @content << numbers
  numbers
end

#render(zip) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/docxi/word/headers/header.rb', line 29

def render(zip)
  zip.put_next_entry("word/#{target}")
  zip.write(Docxi.to_xml(document))

  if !@relationships.empty?
    zip.put_next_entry("word/_rels/#{target}.rels")
    zip.write(Docxi.to_xml(relationships))
  end
end

#table(options = {}, &block) ⇒ Object



67
68
69
70
71
# File 'lib/docxi/word/headers/header.rb', line 67

def table(options={}, &block)
  table = Docxi::Word::Contents::Table.new(options, &block)
  @content << table
  table
end

#targetObject



25
26
27
# File 'lib/docxi/word/headers/header.rb', line 25

def target
  "header#{id}.xml"
end

#text(text, options = {}) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/docxi/word/headers/header.rb', line 46

def text(text, options={})
  options = @options.merge(options)
  element = Docxi::Word::Contents::Paragraph.new(options) do |p|
    p.text(text)
  end
  @content << element
  element
end