Class: DocxGenerator::DSL::Paragraph

Inherits:
Object
  • Object
show all
Defined in:
lib/docx_generator/dsl/paragraph.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ Paragraph

Returns a new instance of Paragraph.

Yields:

  • (_self)

Yield Parameters:



4
5
6
7
8
# File 'lib/docx_generator/dsl/paragraph.rb', line 4

def initialize(options = {}, &block)
  @objects = []
  @options = options
  yield self if block
end

Instance Method Details

#add(*objects) ⇒ Object



34
35
36
37
38
39
# File 'lib/docx_generator/dsl/paragraph.rb', line 34

def add(*objects)
  objects.each do |object|
    @objects << object
  end
  self
end

#alignment(value) ⇒ Object



10
11
12
# File 'lib/docx_generator/dsl/paragraph.rb', line 10

def alignment(value)
  @options[:alignment] = value
end

#generateObject



24
25
26
27
28
29
30
31
32
# File 'lib/docx_generator/dsl/paragraph.rb', line 24

def generate
  text_fragments = generate_text_fragments
  options = generate_paragraph_options
  if options
    Word::Paragraph.new({}, text_fragments.unshift(options))
  else
    Word::Paragraph.new({}, text_fragments)
  end
end

#no_spaceObject



14
15
16
# File 'lib/docx_generator/dsl/paragraph.rb', line 14

def no_space
  @objects << DocxGenerator::Word::Extensions::NoSpace.new
end

#text(text_fragment, options = {}) {|text_object| ... } ⇒ Object

Yields:

  • (text_object)


18
19
20
21
22
# File 'lib/docx_generator/dsl/paragraph.rb', line 18

def text(text_fragment, options = {}, &block)
  text_object = DocxGenerator::DSL::Text.new(text_fragment, options)
  yield text_object if block
  @objects << text_object
end