Class: DocxGenerator::DSL::Text
- Inherits:
-
Object
- Object
- DocxGenerator::DSL::Text
- Defined in:
- lib/docx_generator/dsl/text.rb
Overview
Represent a text fragment with formatting options
Instance Method Summary collapse
-
#bold(value) ⇒ Object
Set whether the text should be in bold or not.
-
#caps(value) ⇒ Object
Set whether the text should be displayed in capital letters.
-
#font(value) ⇒ Object
Set the name of the font.
-
#generate ⇒ DocxGenerator::Word::Run
Generate the XML element objects.
-
#initialize(text_fragment, options = {}) {|_self| ... } ⇒ Text
constructor
Create a new text fragment with the text specified.
-
#italics(value) ⇒ Object
Set whether the text should be in italics or not.
-
#size(value) ⇒ Object
Set the size of the text (in points).
-
#small_caps(value) ⇒ Object
Set whether the text should be displayed in small capital letters.
-
#subscript(value) ⇒ Object
Set whether the text should be in subscript.
-
#superscript(value) ⇒ Object
Set whether the text should be in superscript.
-
#to_s ⇒ Object
Generate the XML representation of the text fragment.
-
#underline(value) ⇒ Object
Set the style of the underline and other options.
Constructor Details
#initialize(text_fragment, options = {}) {|_self| ... } ⇒ Text
Create a new text fragment with the text 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).
18 19 20 21 22 |
# File 'lib/docx_generator/dsl/text.rb', line 18 def initialize(text_fragment, = {}, &block) @text_fragment = text_fragment @options = yield self if block end |
Instance Method Details
#bold(value) ⇒ Object
Set whether the text should be in bold or not.
26 27 28 |
# File 'lib/docx_generator/dsl/text.rb', line 26 def bold(value) @options[:bold] = value end |
#caps(value) ⇒ Object
Set whether the text should be displayed in capital letters.
62 63 64 |
# File 'lib/docx_generator/dsl/text.rb', line 62 def caps(value) @options[:caps] = value end |
#font(value) ⇒ Object
Set the name of the font.
74 75 76 |
# File 'lib/docx_generator/dsl/text.rb', line 74 def font(value) @options[:font] = value end |
#generate ⇒ DocxGenerator::Word::Run
Generate the XML element objects.
80 81 82 83 84 85 86 87 88 |
# File 'lib/docx_generator/dsl/text.rb', line 80 def generate = text = Word::Text.new({}, [@text_fragment]) if Word::Run.new({}, [, text]) else Word::Run.new({}, [text]) end end |
#italics(value) ⇒ Object
Set whether the text should be in italics or not.
32 33 34 |
# File 'lib/docx_generator/dsl/text.rb', line 32 def italics(value) @options[:italics] = value end |
#size(value) ⇒ Object
Set the size of the text (in points).
44 45 46 |
# File 'lib/docx_generator/dsl/text.rb', line 44 def size(value) @options[:size] = value end |
#small_caps(value) ⇒ Object
Set whether the text should be displayed in small capital letters.
68 69 70 |
# File 'lib/docx_generator/dsl/text.rb', line 68 def small_caps(value) @options[:small_caps] = value end |
#subscript(value) ⇒ Object
Set whether the text should be in subscript.
56 57 58 |
# File 'lib/docx_generator/dsl/text.rb', line 56 def subscript(value) @options[:subscript] = value end |
#superscript(value) ⇒ Object
Set whether the text should be in superscript.
50 51 52 |
# File 'lib/docx_generator/dsl/text.rb', line 50 def superscript(value) @options[:superscript] = value end |
#to_s ⇒ Object
Generate the XML representation of the text fragment
91 92 93 |
# File 'lib/docx_generator/dsl/text.rb', line 91 def to_s generate.to_s end |
#underline(value) ⇒ Object
Set the style of the underline and other options. See the specification for more details.
38 39 40 |
# File 'lib/docx_generator/dsl/text.rb', line 38 def underline(value) @options[:underline] = value end |