Class: Sass::Selector::CommaSequence

### Home Classes Methods

### In Files

- lib/sass/selector/comma_sequence.rb

### Parent

Sass::Selector::AbstractSequence

### Methods

- ::new
- #contains_parent_ref?
- #do_extend
- #inspect
- #populate_extends
- #resolve_parent_refs
- #superselector?
- #to_s
- #to_sass_script
- #unify

### Class/Module Index

Quicksearch

- Sass
- Sass::BaseEnvironment
- Sass::CSS
- Sass::CacheStores
- Sass::CacheStores::Base
- Sass::CacheStores::Chain
- Sass::CacheStores::Filesystem
- Sass::CacheStores::Memory
- Sass::CacheStores::Null
- Sass::Callbacks
- Sass::Callbacks::InstanceMethods
- Sass::Engine
- Sass::Engine::Line
- Sass::Environment
- Sass::Exec
- Sass::Exec::Base
- Sass::Exec::SassConvert
- Sass::Exec::SassScss
- Sass::Exec::SassScss::Sass::Plugin.compiler
- Sass::Features
- Sass::Importers
- Sass::Importers::Base
- Sass::Importers::Filesystem
- Sass::Logger
- Sass::Logger::Base
- Sass::Logger::LogLevel
- Sass::Logger::LogLevel::ClassMethods
- Sass::Media
- Sass::Media::Query
- Sass::Media::QueryList
- Sass::Plugin
- Sass::Plugin::Compiler
- Sass::Plugin::Configuration
- Sass::Plugin::MerbBootLoader
- Sass::Plugin::Rack
- Sass::Plugin::StalenessChecker
- Sass::ReadOnlyEnvironment
- Sass::Repl
- Sass::SCSS
- Sass::SCSS::CssParser
- Sass::SCSS::Parser
- Sass::SCSS::RX
- Sass::SCSS::ScriptLexer
- Sass::SCSS::ScriptParser
- Sass::SCSS::StaticParser
- Sass::Script
- Sass::Script::CssLexer
- Sass::Script::CssParser
- Sass::Script::Functions
- Sass::Script::Functions::EvaluationContext
- Sass::Script::Lexer
- Sass::Script::Parser
- Sass::Script::Tree
- Sass::Script::Tree::Funcall
- Sass::Script::Tree::Interpolation
- Sass::Script::Tree::ListLiteral
- Sass::Script::Tree::Literal
- Sass::Script::Tree::MapLiteral
- Sass::Script::Tree::Node
- Sass::Script::Tree::Operation
- Sass::Script::Tree::Selector
- Sass::Script::Tree::StringInterpolation
- Sass::Script::Tree::UnaryOperation
- Sass::Script::Tree::Variable
- Sass::Script::Value
- Sass::Script::Value::ArgList
- Sass::Script::Value::Base
- Sass::Script::Value::Bool
- Sass::Script::Value::Color
- Sass::Script::Value::Helpers
- Sass::Script::Value::List
- Sass::Script::Value::Map
- Sass::Script::Value::Null
- Sass::Script::Value::Number
- Sass::Selector
- Sass::Selector::AbstractSequence
- Sass::Selector::Attribute
- Sass::Selector::Class
- Sass::Selector::CommaSequence
- Sass::Selector::Element
- Sass::Selector::Id
- Sass::Selector::Parent
- Sass::Selector::Placeholder
- Sass::Selector::Pseudo
- Sass::Selector::Sequence
- Sass::Selector::Simple
- Sass::Selector::SimpleSequence
- Sass::Selector::Universal
- Sass::SemiGlobalEnvironment
- Sass::Shared
- Sass::Source
- Sass::Source::Map
- Sass::Source::Map::Mapping
- Sass::Source::Position
- Sass::Source::Range
- Sass::Stack
- Sass::Stack::Frame
- Sass::Supports
- Sass::Supports::Condition
- Sass::Supports::Declaration
- Sass::Supports::Interpolation
- Sass::Supports::Negation
- Sass::Supports::Operator
- Sass::SyntaxError
- Sass::Tree
- Sass::Tree::AtRootNode
- Sass::Tree::CharsetNode
- Sass::Tree::CommentNode
- Sass::Tree::ContentNode
- Sass::Tree::CssImportNode
- Sass::Tree::DebugNode
- Sass::Tree::DirectiveNode
- Sass::Tree::EachNode
- Sass::Tree::ErrorNode
- Sass::Tree::ExtendNode
- Sass::Tree::ForNode
- Sass::Tree::FunctionNode
- Sass::Tree::IfNode
- Sass::Tree::ImportNode
- Sass::Tree::KeyframeRuleNode
- Sass::Tree::MediaNode
- Sass::Tree::MixinDefNode
- Sass::Tree::MixinNode
- Sass::Tree::Node
- Sass::Tree::PropNode
- Sass::Tree::ReturnNode
- Sass::Tree::RootNode
- Sass::Tree::RuleNode
- Sass::Tree::SupportsNode
- Sass::Tree::TraceNode
- Sass::Tree::VariableNode
- Sass::Tree::Visitors
- Sass::Tree::Visitors::Base
- Sass::Tree::Visitors::CheckNesting
- Sass::Tree::Visitors::Convert
- Sass::Tree::Visitors::Cssize
- Sass::Tree::Visitors::Cssize::Bubble
- Sass::Tree::Visitors::DeepCopy
- Sass::Tree::Visitors::Extend
- Sass::Tree::Visitors::Perform
- Sass::Tree::Visitors::SetOptions
- Sass::Tree::Visitors::ToCss
- Sass::Tree::WarnNode
- Sass::Tree::WhileNode
- Sass::UnitConversionError
- Sass::Util
- Sass::Util::CrossPlatformRandom
- Sass::Util::MultibyteStringScanner
- Sass::Util::NormalizedMap
- Sass::Util::SubsetMap
- Sass::Util::Test
- Sass::Version
- ActionController
- ActionController::Base
- Object
- OrderedHash

No matching classes.

# Sass::Selector::CommaSequence

A comma-separated sequence of selectors.

### Attributes

members[R]

The comma-separated selector sequences represented by this class.

@return [Array<Sequence>]

### Public Class Methods

new(seqs) click to toggle source

@param seqs [Array<Sequence>] See {#members}

    # File lib/sass/selector/comma_sequence.rb, line 12
    def initialize(seqs)
      @members = seqs
    end

### Public Instance Methods

contains_parent_ref?() click to toggle source

Returns whether there's a {Parent} selector anywhere in this sequence.

@return [Boolean]

    # File lib/sass/selector/comma_sequence.rb, line 43
    def contains_parent_ref?
      @members.any? {|sel| sel.contains_parent_ref?}
    end

do_extend(extends, parent_directives = [], replace = false, seen = Set.new, original = true) click to toggle source

Non-destrucively extends this selector with the extensions specified in a hash (which should come from {Sass::Tree::Visitors::Cssize}).

@todo Link this to the reference documentation on `@extend`

    when such a thing exists.

@param extends [Sass::Util::SubsetMap{Selector::Simple =>

                                        Sass::Tree::Visitors::Cssize::Extend}]
    The extensions to perform on this selector

@param parent_directives [Array<Sass::Tree::DirectiveNode>]

    The directives containing this selector.

@param replace [Boolean]

    Whether to replace the original selector entirely or include
    it in the result.

@param seen [Set<Array<Selector::Simple>>]

    The set of simple sequences that are currently being replaced.

@param original [Boolean]

    Whether this is the original selector being extended, as opposed to
    the result of a previous extension that's being re-extended.

@return [CommaSequence] A copy of this selector,

    with extensions made according to `extends`

    # File lib/sass/selector/comma_sequence.rb, line 68
    def do_extend(extends, parent_directives = [], replace = false, seen = Set.new,
        original = true)
      CommaSequence.new(members.map do |seq|
        seq.do_extend(extends, parent_directives, replace, seen, original)
      end.flatten)
    end

inspect() click to toggle source

Returns a string representation of the sequence. This is basically the selector string.

@return [String]

    # File lib/sass/selector/comma_sequence.rb, line 157
    def inspect
      members.map {|m| m.inspect}.join(", ")
    end

populate_extends(extends, extendee, extend_node = nil, parent_directives = []) click to toggle source

Populates a subset map that can then be used to extend selectors. This registers an extension with this selector as the extender and `extendee` as the extendee.

@param extends [Sass::Util::SubsetMap{Selector::Simple =>

                                        Sass::Tree::Visitors::Cssize::Extend}]
    The subset map representing the extensions to perform.

@param extendee [CommaSequence] The selector being extended. @param extend_node [Sass::Tree::ExtendNode]

    The node that caused this extension.

@param parent_directives [Array<Sass::Tree::DirectiveNode>]

    The parent directives containing `extend_node`.

@raise [Sass::SyntaxError] if this extension is invalid.

    # File lib/sass/selector/comma_sequence.rb, line 100
    def populate_extends(extends, extendee, extend_node = nil, parent_directives = [])
      extendee.members.each do |seq|
        if seq.members.size > 1
          raise Sass::SyntaxError.new("Can't extend #{seq}: can't extend nested selectors")
        end

        sseq = seq.members.first
        if !sseq.is_a?(Sass::Selector::SimpleSequence)
          raise Sass::SyntaxError.new("Can't extend #{seq}: invalid selector")
        elsif sseq.members.any? {|ss| ss.is_a?(Sass::Selector::Parent)}
          raise Sass::SyntaxError.new("Can't extend #{seq}: can't extend parent selectors")
        end

        sel = sseq.members
        members.each do |member|
          unless member.members.last.is_a?(Sass::Selector::SimpleSequence)
            raise Sass::SyntaxError.new("#{member} can't extend: invalid selector")
          end

          extends[sel] = Sass::Tree::Visitors::Cssize::Extend.new(
            member, sel, extend_node, parent_directives, :not_found)
        end
      end
    end

resolve_parent_refs(super_cseq, implicit_parent = true) click to toggle source

Resolves the {Parent} selectors within this selector by replacing them with the given parent selector, handling commas appropriately.

@param super_cseq [CommaSequence] The parent selector @param implicit_parent [Boolean] Whether the the parent

    selector should automatically be prepended to the resolved
    selector if it contains no parent refs.

@return [CommaSequence] This selector, with parent references resolved @raise [Sass::SyntaxError] If a parent selector is invalid

    # File lib/sass/selector/comma_sequence.rb, line 26
    def resolve_parent_refs(super_cseq, implicit_parent = true)
      if super_cseq.nil?
        if contains_parent_ref?
          raise Sass::SyntaxError.new(
            "Base-level rules cannot contain the parent-selector-referencing character '&'.")
        end
        return self
      end

      CommaSequence.new(Sass::Util.flatten_vertically(@members.map do |seq|
        seq.resolve_parent_refs(super_cseq, implicit_parent).members
      end))
    end

superselector?(cseq) click to toggle source

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 cseq [CommaSequence] @return [Boolean]

    # File lib/sass/selector/comma_sequence.rb, line 83
    def superselector?(cseq)
      cseq.members.all? {|seq1| members.any? {|seq2| seq2.superselector?(seq1)}}
    end

to_s() click to toggle source

@see AbstractSequence#to_s

    # File lib/sass/selector/comma_sequence.rb, line 162
    def to_s
      @members.join(", ").gsub(", \n", ",\n")
    end

to_sass_script() click to toggle source

Returns a SassScript representation of this selector.

@return [Sass::Script::Value::List]

    # File lib/sass/selector/comma_sequence.rb, line 144
    def to_sass_script
      Sass::Script::Value::List.new(members.map do |seq|
        Sass::Script::Value::List.new(seq.members.map do |component|
          next if component == "\n"
          Sass::Script::Value::String.new(component.to_s)
        end.compact, :space)
      end, :comma)
    end

unify(other) click to toggle source

Unifies this with another comma selector to produce a selector that matches (a subset of) the intersection of the two inputs.

@param other [CommaSequence] @return [CommaSequence, nil] The unified selector, or nil if unification failed. @raise [Sass::SyntaxError] If this selector cannot be unified.

    This will only ever occur when a dynamic selector,
    such as {Parent} or {Interpolation}, is used in unification.
    Since these selectors should be resolved
    by the time extension and unification happen,
    this exception will only ever be raised as a result of programmer error

    # File lib/sass/selector/comma_sequence.rb, line 136
    def unify(other)
      results = members.map {|seq1| other.members.map {|seq2| seq1.unify(seq2)}}.flatten.compact
      results.empty? ? nil : CommaSequence.new(results.map {|cseq| cseq.members}.flatten)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.