Class: Wunderbar::IndentedTextNode

Inherits:
TextNode show all
Defined in:
lib/wunderbar/node.rb

Constant Summary

Constants inherited from Node

Node::ESCAPE, Node::VOID

Instance Attribute Summary

Attributes inherited from Node

#attrs, #children, #name, #node, #parent, #text

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from TextNode

#initialize

Methods inherited from Node

#add_child, #initialize, #method_missing, #walk

Constructor Details

This class inherits a constructor from Wunderbar::TextNode

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Wunderbar::Node

Class Method Details

.reflow(indent, line, width) ⇒ Object



203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/wunderbar/node.rb', line 203

def self.reflow(indent, line, width)
  return [line] if line.include? "\n" or not width

  result = []
  while line.length > width
    split = line.rindex(' ', width)
    break if not split or split <= indent.to_s.length
    result << line[0...split]
    line = "#{indent}#{line[split+1..-1]}"
  end

  result << line
end

Instance Method Details

#serialize(options, result, indent) ⇒ Object



217
218
219
220
221
222
223
224
225
226
# File 'lib/wunderbar/node.rb', line 217

def serialize(options, result, indent)
  if indent
    text = CDATANode.normalize(@text, indent)
  else
    text = @text
  end

  result.push *IndentedTextNode.reflow(indent, 
    text.to_s.gsub(/[&<>]/,ESCAPE), options[:width])
end