lib/action_controller/vendor/html-scanner/html/node.rb in actionpack-1.9.1 vs lib/action_controller/vendor/html-scanner/html/node.rb in actionpack-1.10.1
- old
+ new
@@ -120,10 +120,22 @@
end
def validate_conditions(conditions)
Conditions === conditions ? conditions : Conditions.new(conditions)
end
+
+ def ==(node)
+ return false unless self.class == node.class && children.size == node.children.size
+
+ equivalent = true
+
+ children.size.times do |i|
+ equivalent &&= children[i] == node.children[i]
+ end
+
+ equivalent
+ end
class <<self
def parse(parent, line, pos, content, strict=true)
if content !~ /^<\S/
Text.new(parent, line, pos, content)
@@ -236,10 +248,15 @@
match(conditions[:content])
else
nil
end
end
+
+ def ==(node)
+ return false unless super
+ content == node.content
+ end
end
# A Tag is any node that represents markup. It may be an opening tag, a
# closing tag, or a self-closing tag. It has a name, and may have a hash of
# attributes.
@@ -269,11 +286,12 @@
def [](attr)
@attributes ? @attributes[attr] : nil
end
# Returns non-+nil+ if this tag can contain child nodes.
- def childless?
+ def childless?(xml = false)
+ return false if xml && @closing.nil?
!@closing.nil? ||
@name =~ /^(img|br|hr|link|meta|area|base|basefont|
col|frame|input|isindex|param)$/ox
end
@@ -415,11 +433,15 @@
end
end
# count children
if opts = conditions[:children]
- matches = children
+ matches = children.select do |c|
+ c.match(/./) or
+ (c.kind_of?(HTML::Tag) and (c.closing == :self or ! c.childless?))
+ end
+
matches = matches.select { |c| c.match(opts[:only]) } if opts[:only]
opts.each do |key, value|
next if key == :only
case key
when :count
@@ -462,11 +484,16 @@
end
true
end
+ def ==(node)
+ return false unless super
+ return false unless closing == node.closing && self.name == node.name
+ attributes == node.attributes
+ end
+
private
-
# Match the given value to the given condition.
def match_condition(value, condition)
case condition
when String
value && value.index(condition)