Class: DocxGenerator::DSL::Paragraph
- Inherits:
-
Object
- Object
- DocxGenerator::DSL::Paragraph
- Defined in:
- lib/docx_generator/dsl/paragraph.rb
Overview
Represent a paragraph with formatting options
Instance Method Summary collapse
-
#add(*objects) ⇒ DocxGenerator::DSL::Paragraph
Add other objects to the paragraph.
-
#alignment(value) ⇒ Object
Set the alignment of the paragraph.
-
#generate ⇒ DocxGenerator::Word::Paragraph
Generate the XML element objects.
-
#indentation(properties) ⇒ Object
Set various indentation properties for the paragraph.
-
#initialize(options = {}) {|_self| ... } ⇒ Paragraph
constructor
Create a new paragraph with the formatting options specified.
-
#newline ⇒ Object
Add a newline.
-
#no_space ⇒ Object
Prevent the addition of a space between two text fragments.
-
#spacing(options) ⇒ Object
Set various spacing options for the paragraph.
-
#tab ⇒ Object
Add a tabulation.
-
#tabs(tab_stops) ⇒ Object
Set custom tabulation stops.
-
#text(text_fragment, options = {}) {|text_object| ... } ⇒ Object
Add a new text fragment to the paragraph.
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ Paragraph
Create a new paragraph with the formatting options specified. The formatting properties can be passed with a Hash or they could be set by calling the methods on the object (either in the block or not).
12 13 14 15 16 |
# File 'lib/docx_generator/dsl/paragraph.rb', line 12 def initialize( = {}, &block) @objects = [] @options = yield self if block end |
Instance Method Details
#add(*objects) ⇒ DocxGenerator::DSL::Paragraph
Add other objects to the paragraph.
81 82 83 84 85 86 |
# File 'lib/docx_generator/dsl/paragraph.rb', line 81 def add(*objects) objects.each do |object| @objects << object end self end |
#alignment(value) ⇒ Object
Set the alignment of the paragraph. See the specification for more details.
20 21 22 |
# File 'lib/docx_generator/dsl/paragraph.rb', line 20 def alignment(value) @options[:alignment] = value end |
#generate ⇒ DocxGenerator::Word::Paragraph
Generate the XML element objects.
68 69 70 71 72 73 74 75 76 |
# File 'lib/docx_generator/dsl/paragraph.rb', line 68 def generate text_fragments = generate_text_fragments = if Word::Paragraph.new({}, text_fragments.unshift()) else Word::Paragraph.new({}, text_fragments) end end |
#indentation(properties) ⇒ Object
Set various indentation properties for the paragraph. See the specification for more details.
32 33 34 |
# File 'lib/docx_generator/dsl/paragraph.rb', line 32 def indentation(properties) @options[:indentation] = properties end |
#newline ⇒ Object
Add a newline
48 49 50 |
# File 'lib/docx_generator/dsl/paragraph.rb', line 48 def newline @objects << DocxGenerator::Word::Extensions::Newline.new end |
#no_space ⇒ Object
Prevent the addition of a space between two text fragments.
43 44 45 |
# File 'lib/docx_generator/dsl/paragraph.rb', line 43 def no_space @objects << DocxGenerator::Word::Extensions::NoSpace.new end |
#spacing(options) ⇒ Object
Set various spacing options for the paragraph. See the specification for more details.
26 27 28 |
# File 'lib/docx_generator/dsl/paragraph.rb', line 26 def spacing() @options[:spacing] = end |
#tab ⇒ Object
Add a tabulation
53 54 55 |
# File 'lib/docx_generator/dsl/paragraph.rb', line 53 def tab @objects << DocxGenerator::Word::Tab.new end |
#tabs(tab_stops) ⇒ Object
Set custom tabulation stops. See the specification for more details.
38 39 40 |
# File 'lib/docx_generator/dsl/paragraph.rb', line 38 def tabs(tab_stops) @options[:tabs] = tab_stops end |
#text(text_fragment, options = {}) {|text_object| ... } ⇒ Object
Add a new text fragment to the paragraph.
60 61 62 63 64 |
# File 'lib/docx_generator/dsl/paragraph.rb', line 60 def text(text_fragment, = {}, &block) text_object = DocxGenerator::DSL::Text.new(text_fragment, ) yield text_object if block @objects << text_object end |