Class: PureDocx::XmlGenerators::Text

Inherits:
Base
  • Object
show all
Defined in:
lib/puredocx/xml_generators/text.rb

Constant Summary collapse

DEFAULT_TEXT_SIZE =
28
DEFAULT_TEXT_ALIGN =
'left'.freeze

Instance Attribute Summary collapse

Attributes inherited from Base

#content, #rels_constructor

Instance Method Summary collapse

Methods inherited from Base

#xml

Constructor Details

#initialize(content, rels_constructor, arguments = {}) ⇒ Text

Returns a new instance of Text.



10
11
12
13
14
15
16
17
# File 'lib/puredocx/xml_generators/text.rb', line 10

def initialize(content, rels_constructor, arguments = {})
  super(nil, rels_constructor)
  @content       = CGI.escapeHTML(content)
  @bold_enable   = [*arguments[:style]].include?(:bold)
  @italic_enable = [*arguments[:style]].include?(:italic)
  @align         = arguments[:align] || DEFAULT_TEXT_ALIGN
  @size          = arguments[:size]  || DEFAULT_TEXT_SIZE
end

Instance Attribute Details

#alignObject (readonly)

Returns the value of attribute align.



8
9
10
# File 'lib/puredocx/xml_generators/text.rb', line 8

def align
  @align
end

#bold_enableObject (readonly)

Returns the value of attribute bold_enable.



8
9
10
# File 'lib/puredocx/xml_generators/text.rb', line 8

def bold_enable
  @bold_enable
end

#italic_enableObject (readonly)

Returns the value of attribute italic_enable.



8
9
10
# File 'lib/puredocx/xml_generators/text.rb', line 8

def italic_enable
  @italic_enable
end

#sizeObject (readonly)

Returns the value of attribute size.



8
9
10
# File 'lib/puredocx/xml_generators/text.rb', line 8

def size
  @size
end

Instance Method Details

#paramsObject



19
20
21
22
23
24
25
26
27
# File 'lib/puredocx/xml_generators/text.rb', line 19

def params
  {
    '{TEXT}'          => content,
    '{ALIGN}'         => align,
    '{BOLD_ENABLE}'   => bold_enable,
    '{ITALIC_ENABLE}' => italic_enable,
    '{SIZE}'          => size
  }
end

#templateObject



29
30
31
# File 'lib/puredocx/xml_generators/text.rb', line 29

def template
  File.read(DocArchive.template_path('paragraph.xml'))
end