Class: Sablon::Content::String

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

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) ⇒ String

Returns a new instance of String.



50
51
52
# File 'lib/sablon/content.rb', line 50

def initialize(value)
  super value.to_s
end

Instance Attribute Details

#stringObject

Returns the value of attribute string

Returns:

  • (Object)

    the current value of string



43
44
45
# File 'lib/sablon/content.rb', line 43

def string
  @string
end

Class Method Details

.idObject



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

def self.id; :string end

.wraps?(value) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/sablon/content.rb', line 46

def self.wraps?(value)
  value.respond_to?(:to_s)
end

Instance Method Details

#append_to(paragraph, display_node) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/sablon/content.rb', line 54

def append_to(paragraph, display_node)
  string.scan(/[^\n]+|\n/).reverse.each do |part|
    if part == "\n"
      display_node.add_next_sibling Nokogiri::XML::Node.new "w:br", display_node.document
    else
      text_part = display_node.dup
      text_part.content = part
      display_node.add_next_sibling text_part
    end
  end
end