Module: Docx::Elements::Element

Included in:
Bookmark, Containers::Paragraph, Containers::TextRun, Text
Defined in:
lib/docx/elements/element.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

DEFAULT_TAG =
''

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nodeObject

Returns the value of attribute node.



15
16
17
# File 'lib/docx/elements/element.rb', line 15

def node
  @node
end

Class Method Details

.included(base) ⇒ Object



10
11
12
13
# File 'lib/docx/elements/element.rb', line 10

def self.included(base)
  base.extend(ClassMethods)
  base.const_set(:TAG, Element::DEFAULT_TAG) unless base.const_defined?(:TAG)
end

Instance Method Details

#append_to(element) ⇒ Object

Insertion methods Insert node as last child



30
31
32
33
# File 'lib/docx/elements/element.rb', line 30

def append_to(element)
  @node = element.node.add_child(@node)
  self
end

#copyObject

Creation/edit methods



53
54
55
# File 'lib/docx/elements/element.rb', line 53

def copy
  self.class.new(@node.dup)
end

#insert_after(element) ⇒ Object



41
42
43
44
45
# File 'lib/docx/elements/element.rb', line 41

def insert_after(element)
  # Returns newly re-parented node
  @node = element.node.add_next_sibling(@node)
  self
end

#insert_before(element) ⇒ Object



47
48
49
50
# File 'lib/docx/elements/element.rb', line 47

def insert_before(element)
  @node = element.node.add_previous_sibling(@node)
  self
end

#parent(type = '*') ⇒ Object

TODO: Should create a docx object from this



19
20
21
# File 'lib/docx/elements/element.rb', line 19

def parent(type = '*')
  @node.at_xpath("./parent::#{type}")
end

#parent_paragraphObject

TODO: Should create a docx paragraph from this



24
25
26
# File 'lib/docx/elements/element.rb', line 24

def parent_paragraph
  Elements::Containers::Paragraph.new(parent('w:p'))
end

#prepend_to(element) ⇒ Object

Insert node as first child (after properties)



36
37
38
39
# File 'lib/docx/elements/element.rb', line 36

def prepend_to(element)
  @node = element.node.properties.add_next_sibling(@node)
  self
end