Skip to content

Commit

Permalink
[Sass] Document the #superselector? methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 committed Apr 28, 2010
1 parent 25736cf commit ab24417
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/sass/selector/sequence.rb
Expand Up @@ -87,6 +87,16 @@ def do_extend(extends, supers = [])
Haml::Util.flatten(paths.map {|path| weave(path)}, 1).map {|p| Sequence.new(p)}
end

# Returns whether or not this selector matches all elements
# that the given selector matches (as well as possibly more).
#
# @example
# (.foo).superselector?(.foo.bar) #=> true
# (.foo).superselector?(.bar) #=> false
# (.bar .foo).superselector?(.foo) #=> false
#
# @param sseq [SimpleSequence]
# @return [Boolean]
def superselector?(sseq)
return false unless members.size == 1
members.last.superselector?(sseq)
Expand Down
9 changes: 9 additions & 0 deletions lib/sass/selector/simple_sequence.rb
Expand Up @@ -99,6 +99,15 @@ def unify(sels)
SimpleSequence.new(sseq)
end

# Returns whether or not this selector matches all elements
# that the given selector matches (as well as possibly more).
#
# @example
# (.foo).superselector?(.foo.bar) #=> true
# (.foo).superselector?(.bar) #=> false
#
# @param sseq [SimpleSequence]
# @return [Boolean]
def superselector?(sseq)
(base.nil? || base.eql?(sseq.base)) && rest.subset?(sseq.rest)
end
Expand Down

0 comments on commit ab24417

Please sign in to comment.