vendor/rails/actionpack/lib/action_controller/vendor/html-scanner/html/selector.rb in radiant-0.6.4 vs vendor/rails/actionpack/lib/action_controller/vendor/html-scanner/html/selector.rb in radiant-0.6.5
- old
+ new
@@ -238,23 +238,28 @@
# Throws InvalidSelectorError is the selector expression is invalid.
def initialize(selector, *values)
raise ArgumentError, "CSS expression cannot be empty" if selector.empty?
@source = ""
values = values[0] if values.size == 1 && values[0].is_a?(Array)
+
# We need a copy to determine if we failed to parse, and also
# preserve the original pass by-ref statement.
statement = selector.strip.dup
+
# Create a simple selector, along with negation.
simple_selector(statement, values).each { |name, value| instance_variable_set("@#{name}", value) }
+ @alternates = []
+ @depends = nil
+
# Alternative selector.
if statement.sub!(/^\s*,\s*/, "")
second = Selector.new(statement, values)
- (@alternates ||= []) << second
+ @alternates << second
# If there are alternate selectors, we group them in the top selector.
if alternates = second.instance_variable_get(:@alternates)
- second.instance_variable_set(:@alternates, nil)
+ second.instance_variable_set(:@alternates, [])
@alternates.concat alternates
end
@source << " , " << second.to_s
# Sibling selector: create a dependency into second selector that will
# match element immediately following this one.
@@ -410,11 +415,11 @@
matches = matched ? [element] : nil
end
# If this selector is part of the group, try all the alternative
# selectors (unless first_only).
- if @alternates && (!first_only || !matches)
+ if !first_only || !matches
@alternates.each do |alternate|
break if matches && first_only
if subset = alternate.match(element, first_only)
if matches
matches.concat subset
@@ -787,18 +792,18 @@
# Called to create a dependent selector (sibling, descendant, etc).
# Passes the remainder of the statement that will be reduced to zero
# eventually, and array of substitution values.
#
# This method is called from four places, so it helps to put it here
- # for resue. The only logic deals with the need to detect comma
+ # for reuse. The only logic deals with the need to detect comma
# separators (alternate) and apply them to the selector group of the
# top selector.
def next_selector(statement, values)
second = Selector.new(statement, values)
# If there are alternate selectors, we group them in the top selector.
if alternates = second.instance_variable_get(:@alternates)
- second.instance_variable_set(:@alternates, nil)
- (@alternates ||= []).concat alternates
+ second.instance_variable_set(:@alternates, [])
+ @alternates.concat alternates
end
second
end
end