Class: Sablon::Content::WordML

Inherits:
Struct
  • Object
show all
Includes:
Sablon::Content
Defined in:
lib/sablon/content.rb

Overview

handles direct addition of WordML to the document template

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Sablon::Content

make, register, remove, wrap

Constructor Details

#initialize(value) ⇒ WordML

Returns a new instance of WordML.



76
77
78
# File 'lib/sablon/content.rb', line 76

def initialize(value)
  super Nokogiri::XML.fragment(value)
end

Instance Attribute Details

#xmlObject

Returns the value of attribute xml

Returns:

  • (Object)

    the current value of xml



71
72
73
# File 'lib/sablon/content.rb', line 71

def xml
  @xml
end

Class Method Details

.idObject



73
# File 'lib/sablon/content.rb', line 73

def self.id; :word_ml end

.wraps?(value) ⇒ Boolean

Returns:

  • (Boolean)


74
# File 'lib/sablon/content.rb', line 74

def self.wraps?(value) false end

Instance Method Details

#==(other) ⇒ Object

This allows proper equality checks with other WordML content objects. Due to the fact the ‘xml` attribute is a live Nokogiri object the default `==` comparison returns false unless it is the exact same object being compared. This method instead checks if the XML being added to the document is the same when the `other` object is an instance of the WordML content class.



99
100
101
102
103
104
105
# File 'lib/sablon/content.rb', line 99

def ==(other)
  if other.class == self.class
    xml.to_s == other.xml.to_s
  else
    super
  end
end

#append_to(paragraph, display_node, env) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/sablon/content.rb', line 80

def append_to(paragraph, display_node, env)
  # if all nodes are inline then add them to the existing paragraph
  # otherwise replace the paragraph with the new content.
  if all_inline?
    pr_tag = display_node.parent.at_xpath('./w:rPr')
    add_siblings_to(display_node.parent, pr_tag)
    display_node.parent.remove
  else
    add_siblings_to(paragraph)
    paragraph.remove
  end
end