Class: Docxtor::Document::Paragraph

Inherits:
Element
  • Object
show all
Defined in:
lib/docxtor/document/paragraph.rb

Direct Known Subclasses

Heading

Constant Summary collapse

STYLE =
'a5'
PROPERTIES =
{
  :p => {
    :style => 'pStyle',
    :align => 'jc',
    :font_size => 'sz',
    :font_size_complex => 'szCs',
    :spacing => {
      :name => 'spacing',
      :before => 'before',
      :after => 'after'
    },
    :indent => {
      :name => 'ind',
      :start => 'start',
      :end => 'end',
      :hanging => 'hanging'
    }
  },
  :r => {
    :bold => 'b',
    :italic => 'i',
    :underline => 'u'
  }
}
PLAIN_PROPERTIES =
PROPERTIES[:p].reject {|k,v| v.is_a? Hash}
NESTED_PROPERTIES =
PROPERTIES[:p].reject {|k,v| !v.is_a? Hash}

Instance Attribute Summary

Attributes inherited from Element

#elements, #xml

Instance Method Summary collapse

Methods inherited from Element

#initialize, map

Constructor Details

This class inherits a constructor from Docxtor::Document::Element

Instance Method Details

#after_initialize(*args) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/docxtor/document/paragraph.rb', line 38

def after_initialize(*args)
  @contents = []
  @contents << args.shift if args.first.is_a? String

  create_params(args.shift || {})

  NESTED_PROPERTIES.each do |name, element|
    @params[name] ||= {}
  end
  @params[:space] ||= 'default'
end

#aliasesObject



87
88
89
90
91
92
93
# File 'lib/docxtor/document/paragraph.rb', line 87

def aliases
  {
    :b => :bold,
    :i => :italic,
    :u => :underline
  }
end

#line_breakObject Also known as: br



75
76
77
# File 'lib/docxtor/document/paragraph.rb', line 75

def line_break
  @contents << :br
end

#preserve_whitespaceObject



79
80
81
# File 'lib/docxtor/document/paragraph.rb', line 79

def preserve_whitespace
  @params[:space] = 'preserve'
end

#propertiesObject



71
72
73
# File 'lib/docxtor/document/paragraph.rb', line 71

def properties
  PROPERTIES
end

#render(xml) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/docxtor/document/paragraph.rb', line 50

def render(xml)
  super
  write_element(:p) do
    write_element(:r) do
      write_contents
    end
  end
end

#write(text) ⇒ Object Also known as: w



83
84
85
# File 'lib/docxtor/document/paragraph.rb', line 83

def write(text)
  @contents << text
end