class Wunderbar::CDATANode
Public Class Methods
normalize(data, indent='')
click to toggle source
# File lib/wunderbar/node.rb, line 275 def self.normalize(data, indent='') data = data.sub(/\n\s*\Z/, '').sub(/\A\s*\n/, '') unindent = data.sub(/s+\Z/,'').scan(/^ *\S/).map(&:length).min || 0 before = ::Regexp.new('^'.ljust(unindent)) data.gsub! before, indent data.gsub!(/^#{indent}$/, '') if unindent == 0 data end
Public Instance Methods
serialize(options = {}, result = [], indent='')
click to toggle source
Calls superclass method
Wunderbar::Node#serialize
# File lib/wunderbar/node.rb, line 286 def serialize(options = {}, result = [], indent='') if @text and @text.include? "\n" tindent = (indent ? "#{indent}#{options[:indent]}" : indent) children.unshift CDATANode.normalize(@text, tindent).rstrip @text = nil end if @text and @text =~ /[<^>]/ indent += options[:indent] if indent children.unshift @text.gsub(/^/, indent).gsub(/^ +$/,'').rstrip @text = nil super(options.merge(pre: pre, post: post), result, indent) elsif children && children.any? {|node| String===node && node =~ /[<^>]/} super(options.merge(pre: pre, post: post), result, indent) else super end end