Class: Docxi::Word::Contents::Paragraph

Inherits:
Object
  • Object
show all
Defined in:
lib/docxi/word/contents/paragraph.rb

Defined Under Namespace

Classes: Hyperlink

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Paragraph

Returns a new instance of Paragraph.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/docxi/word/contents/paragraph.rb', line 8

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

  if block_given?
    yield self
  else

  end
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



7
8
9
# File 'lib/docxi/word/contents/paragraph.rb', line 7

def content
  @content
end

#idObject

Returns the value of attribute id.



7
8
9
# File 'lib/docxi/word/contents/paragraph.rb', line 7

def id
  @id
end

#optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/docxi/word/contents/paragraph.rb', line 7

def options
  @options
end

#relationshipsObject

Returns the value of attribute relationships.



7
8
9
# File 'lib/docxi/word/contents/paragraph.rb', line 7

def relationships
  @relationships
end

Instance Method Details

#br(options = {}) ⇒ Object



104
105
106
107
108
# File 'lib/docxi/word/contents/paragraph.rb', line 104

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

#content_typeObject



20
21
22
# File 'lib/docxi/word/contents/paragraph.rb', line 20

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

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



98
99
100
101
102
# File 'lib/docxi/word/contents/paragraph.rb', line 98

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


29
30
31
32
# File 'lib/docxi/word/contents/paragraph.rb', line 29

def hyperlink(text,link,id)
  text = Hyperlink.new(text, link, id)
  @content << text
end

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



116
117
118
119
120
# File 'lib/docxi/word/contents/paragraph.rb', line 116

def image(image, options={})
  img = Docxi::Word::Contents::Image.new(image, options)
  @content << img
  img
end

#render(xml) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/docxi/word/contents/paragraph.rb', line 64

def render(xml)
  xml['w'].p do
    xml['w'].pPr do
      xml['w'].jc( 'w:val' => @options[:align]) if @options[:align]
      xml['w'].shd( 'w:val' => 'clear','w:fill' => @options[:fill] ) if @options[:fill]
      xml['w'].ind( 'w:left' => @options[:left], 'w:right' => @options[:right] ) if @options[:left] and @options[:right]
      if options[:ul]
        xml['w'].numPr do
          xml['w'].ilvl( 'w:val' => 0 )
          xml['w'].numId( 'w:val' => 1 )
        end
      end
      if options[:bottom]
        xml['w'].pBdr do
          xml['w'].top( 'w:val' => "nil")
          xml['w'].left('w:val' => "nil")
          xml['w'].bottom('w:val'=>"single", 'w:sz'=>"4", 'w:space'=>"1", 'w:color'=>"000000")
          xml['w'].right('w:val'=>"nil")
        end
      end
    end
    @content.each do |element|
      element.render(xml)
    end
  end
end

#tab(options = {}) ⇒ Object



110
111
112
113
114
# File 'lib/docxi/word/contents/paragraph.rb', line 110

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

#targetObject



24
25
26
# File 'lib/docxi/word/contents/paragraph.rb', line 24

def target
  "document.xml"
end

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



91
92
93
94
95
96
# File 'lib/docxi/word/contents/paragraph.rb', line 91

def text(text, options={})
  options = @options.merge(options)
  text = Docxi::Word::Contents::Text.new(text, options)
  @content << text
  text
end