Skip to content

Commit

Permalink
Support :-moz-any.
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 committed Jun 11, 2010
1 parent ef92ec6 commit 81feb13
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 10 deletions.
5 changes: 5 additions & 0 deletions doc-src/SASS_CHANGELOG.md
Expand Up @@ -28,6 +28,11 @@ In anticipation of wider browser support, in fact,
*any* function named `-*-calc` (such as `-webkit-calc` or `-ms-calc`)
will be parsed the same as the `calc` function.

## `:-moz-any` Support

The [`:-moz-any` pseudoclass selector](http://hacks.mozilla.org/2010/05/moz-any-selector-grouping/)
is now parsed by Sass.

## Rails 3 Support

Support for Rails 3 versions prior to beta 4 has been removed.
Expand Down
4 changes: 2 additions & 2 deletions lib/sass/scss/parser.rb
Expand Up @@ -544,12 +544,12 @@ def pseudo_expr
end

def negation
return unless tok(NOT)
return unless name = tok(NOT) || tok(MOZ_ANY)
ss
@expected = "selector"
sel = selector_comma_sequence
tok!(/\)/)
Selector::Negation.new(sel)
Selector::SelectorPseudoClass.new(name[1...-1], sel)
end

def declaration
Expand Down
1 change: 1 addition & 0 deletions lib/sass/scss/rx.rb
Expand Up @@ -109,6 +109,7 @@ def self.quote(str, flags = 0)
# Custom
HEXCOLOR = /\#[0-9a-fA-F]+/
INTERP_START = /#\{/
MOZ_ALL = quote(":-moz-any(", Regexp::IGNORECASE)

STRING1_NOINTERP = /\"((?:[^\n\r\f\\"#]|#(?!\{)|\\#{NL}|#{ESCAPE})*)\"/
STRING2_NOINTERP = /\'((?:[^\n\r\f\\'#]|#(?!\{)|\\#{NL}|#{ESCAPE})*)\'/
Expand Down
20 changes: 14 additions & 6 deletions lib/sass/selector.rb
Expand Up @@ -332,21 +332,29 @@ def unify(sels)
end
end

# A negation pseudoclass selector (e.g. `:not(.foo)`).
class Negation < Simple
# The selector to negate.
# A pseudoclass selector whose argument is itself a selector
# (e.g. `:not(.foo)` or `:-moz-all(.foo, .bar)`).
class SelectorPseudoClass < Simple
# The name of the pseudoclass.
#
# @return [String]
attr_reader :name

# The selector argument.
#
# @return [Selector::Sequence]
attr_reader :selector

# @param [Selector::Sequence] The selector to negate
def initialize(selector)
# @param [String] The name of the pseudoclass
# @param [Selector::Sequence] The selector argument
def initialize(name, selector)
@name = name
@selector = selector
end

# @see Selector#to_a
def to_a
[":not("] + @selector.to_a + [")"]
[":", @name, "("] + @selector.to_a + [")"]
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/sass/selector/simple.rb
Expand Up @@ -78,10 +78,10 @@ def unify(sels)
return sels if sels.any? {|sel2| eql?(sel2)}
sels_with_ix = Haml::Util.enum_with_index(sels)
_, i =
if self.is_a?(Pseudo) || self.is_a?(Negation)
if self.is_a?(Pseudo) || self.is_a?(SelectorPseudoClass)
sels_with_ix.find {|sel, _| sel.is_a?(Pseudo) && sels.last.type == :element}
else
sels_with_ix.find {|sel, _| sel.is_a?(Pseudo) || sel.is_a?(Negation)}
sels_with_ix.find {|sel, _| sel.is_a?(Pseudo) || sel.is_a?(SelectorPseudoClass)}
end
return sels + [self] unless i
return sels[0...i] + [self] + sels[i..-1]
Expand Down
6 changes: 6 additions & 0 deletions test/sass/scss/css_test.rb
Expand Up @@ -714,6 +714,12 @@ def test_negation_selectors
assert_selector_parses(':not(h1, h2, h3)')
end

def test_moz_any_selector
assert_selector_parses(':-moz-any(h1, h2, h3)')
assert_selector_parses(':-moz-any(.foo)')
assert_selector_parses(':-moz-any(foo bar, .baz > .bang)')
end

def test_namespaced_selectors
assert_selector_parses('foo|E')
assert_selector_parses('*|E')
Expand Down

0 comments on commit 81feb13

Please sign in to comment.