Class: Sablon::Content::String

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

Overview

Handles simple text replacement of fields in the 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) ⇒ String

Returns a new instance of String.



53
54
55
# File 'lib/sablon/content.rb', line 53

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



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

def string
  @string
end

Class Method Details

.idObject



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

def self.id; :string end

.wraps?(value) ⇒ Boolean

Returns:

  • (Boolean)


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

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

Instance Method Details

#append_to(paragraph, display_node, env) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/sablon/content.rb', line 57

def append_to(paragraph, display_node, env)
  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