Class: Sablon::Content::String
- Inherits:
-
Struct
- Object
- Struct
- Sablon::Content::String
- Includes:
- Sablon::Content
- Defined in:
- lib/sablon/content.rb
Overview
Handles simple text replacement of fields in the template
Instance Attribute Summary collapse
-
#string ⇒ Object
Returns the value of attribute string.
Class Method Summary collapse
Instance Method Summary collapse
- #append_to(paragraph, display_node, env) ⇒ Object
-
#initialize(value) ⇒ String
constructor
A new instance of String.
Methods included from Sablon::Content
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
#string ⇒ Object
Returns the value of attribute string
46 47 48 |
# File 'lib/sablon/content.rb', line 46 def string @string end |
Class Method Details
.id ⇒ Object
48 |
# File 'lib/sablon/content.rb', line 48 def self.id; :string end |
.wraps?(value) ⇒ 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 |