Class: Docxer::Word::Contents::Paragraph

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

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
# File 'lib/docxer/word/contents/paragraph.rb', line 8

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

  if block_given?
    yield self
  else

  end
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



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

def content
  @content
end

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#br(options = {}) ⇒ Object



43
44
45
46
47
# File 'lib/docxer/word/contents/paragraph.rb', line 43

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

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



49
50
51
52
53
# File 'lib/docxer/word/contents/paragraph.rb', line 49

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

#render(xml) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/docxer/word/contents/paragraph.rb', line 19

def render(xml)
  xml['w'].p do
    xml['w'].pPr do
      xml['w'].jc( 'w:val' => @options[:align]) if @options[:align]
      if options[:ul]
        xml['w'].numPr do
          xml['w'].ilvl( 'w:val' => 0 )
          xml['w'].numId( 'w:val' => 1 )
        end
      end
    end
    @content.each do |element|
      element.render(xml)
    end
  end
end

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



36
37
38
39
40
41
# File 'lib/docxer/word/contents/paragraph.rb', line 36

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