Class Sass::Selector::Simple
In: lib/sass/selector/simple.rb
Parent: Object
Haml::Util Engine Color SyntaxError UnitConversionError StandardError AbstractSequence CommaSequence Sequence SimpleSequence Simple Parent Universal Class Negation Id Pseudo Attribute Interpolation Element Node Operation Literal UnaryOperation StringInterpolation Funcall Variable Interpolation Lexer CssLexer Number String Bool Parser Parser CssParser EvaluationContext StaticParser SassParser CssParser Node DebugNode IfNode CommentNode ForNode PropNode MixinNode DirectiveNode VariableNode RootNode WarnNode ExtendNode RuleNode MixinDefNode WhileNode Enumerable ImportNode Merb::BootLoader MerbBootLoader Repl CSS Environment Rack StalenessChecker lib/sass/repl.rb lib/sass/css.rb lib/sass/environment.rb lib/sass/error.rb lib/sass/engine.rb lib/sass/selector/simple_sequence.rb lib/sass/selector/abstract_sequence.rb lib/sass/selector/sequence.rb lib/sass/selector/comma_sequence.rb lib/sass/selector/simple.rb lib/sass/selector.rb Selector lib/sass/script/css_parser.rb lib/sass/script/lexer.rb lib/sass/script/color.rb lib/sass/script/string.rb lib/sass/script/unary_operation.rb lib/sass/script/variable.rb lib/sass/script/funcall.rb lib/sass/script/string_interpolation.rb lib/sass/script/operation.rb lib/sass/script/bool.rb lib/sass/script/parser.rb lib/sass/script/node.rb lib/sass/script/literal.rb lib/sass/script/interpolation.rb lib/sass/script/css_lexer.rb lib/sass/script/number.rb lib/sass/script/functions.rb Functions Script lib/sass/scss/sass_parser.rb lib/sass/scss/static_parser.rb lib/sass/scss/parser.rb lib/sass/scss/css_parser.rb ScriptParser ScriptLexer RX SCSS Files Callbacks lib/sass/tree/while_node.rb lib/sass/tree/if_node.rb lib/sass/tree/mixin_def_node.rb lib/sass/tree/debug_node.rb lib/sass/tree/root_node.rb lib/sass/tree/for_node.rb lib/sass/tree/import_node.rb lib/sass/tree/prop_node.rb lib/sass/tree/node.rb lib/sass/tree/comment_node.rb lib/sass/tree/extend_node.rb lib/sass/tree/mixin_node.rb lib/sass/tree/warn_node.rb lib/sass/tree/directive_node.rb lib/sass/tree/rule_node.rb lib/sass/tree/variable_node.rb Tree lib/sass/plugin/rack.rb lib/sass/plugin/staleness_checker.rb lib/sass/plugin/merb.rb Plugin Sass dot/m_61_0.png

The abstract superclass for simple selectors (that is, those that don‘t compose multiple selectors).

Methods

==   eql?   hash   inspect   to_a   unify   unify_namespaces  

Attributes

filename  [RW]  The name of the file in which this selector was declared, or `nil` if it was not declared in a file (e.g. on stdin).

@return [String, nil]

line  [RW]  The line of the Sass template on which this selector was declared.

@return [Fixnum]

Public Instance methods

==(other)

Alias for eql?

Checks equality between this and another object.

By default, this is based on the value of \{to_a}, so if that contains information irrelevant to the identity of the selector, this should be overridden.

@param other [Object] The object to test equality against @return [Boolean] Whether or not this is equal to `other`

[Source]

    # File lib/sass/selector/simple.rb, line 55
55:       def eql?(other)
56:         other.class == self.class && other.hash == self.hash && other.to_a.eql?(to_a)
57:       end

Returns a hash code for this selector object.

By default, this is based on the value of \{to_a}, so if that contains information irrelevant to the identity of the selector, this should be overridden.

@return [Fixnum]

[Source]

    # File lib/sass/selector/simple.rb, line 43
43:       def hash
44:         @_hash ||= to_a.hash
45:       end

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

@return [String]

[Source]

    # File lib/sass/selector/simple.rb, line 32
32:       def inspect
33:         to_a.map {|e| e.is_a?(Sass::Script::Node) ? "\#{#{e.to_sass}}" : e}.join
34:       end

Returns a representation of the node as an array of strings and potentially {Sass::Script::Node}s (if there‘s interpolation in the selector). When the interpolation is resolved and the strings are joined together, this will be the string representation of this node.

@return [Array<String, Sass::Script::Node>]

[Source]

    # File lib/sass/selector/simple.rb, line 24
24:       def to_a
25:         raise NotImplementedError.new("All subclasses of Sass::Selector::Simple must override #to_a.")
26:       end

Unifies this selector with a {SimpleSequence}’s {SimpleSequence#members members array}, returning another `SimpleSequence` members array that matches both this selector and the input selector.

By default, this just appends this selector to the end of the array (or returns the original array if this selector already exists in it).

@param sels [Array<Simple>] A {SimpleSequence}’s {SimpleSequence#members members array} @return [Array<Simple>, nil] A {SimpleSequence} {SimpleSequence#members members array}

  matching both `sels` and this selector,
  or `nil` if this is impossible (e.g. unifying `#foo` and `#bar`)

@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

[Source]

    # File lib/sass/selector/simple.rb, line 77
77:       def unify(sels)
78:         return sels if sels.any? {|sel2| eql?(sel2)}
79:         sels_with_ix = Haml::Util.enum_with_index(sels)
80:         _, i =
81:           if self.is_a?(Pseudo) || self.is_a?(Negation)
82:             sels_with_ix.find {|sel, _| sel.is_a?(Pseudo) && sels.last.type == :element}
83:           else
84:             sels_with_ix.find {|sel, _| sel.is_a?(Pseudo) || sel.is_a?(Negation)}
85:           end
86:         return sels + [self] unless i
87:         return sels[0...i] + [self] + sels[i..-1]
88:       end

Protected Instance methods

Unifies two namespaces, returning a namespace that works for both of them if possible.

@param ns1 [String, nil] The first namespace.

  `nil` means none specified, e.g. `foo`.
  The empty string means no namespace specified, e.g. `|foo`.
  `"*"` means any namespace is allowed, e.g. `*|foo`.

@param ns2 [String, nil] The second namespace. See `ns1`. @return [Array(String or nil, Boolean)]

  The first value is the unified namespace, or `nil` for no namespace.
  The second value is whether or not a namespace that works for both inputs
  could be found at all.
  If the second value is `false`, the first should be ignored.

[Source]

     # File lib/sass/selector/simple.rb, line 105
105:       def unify_namespaces(ns1, ns2)
106:         return nil, false unless ns1 == ns2 || ns1.nil? || ns1 == ['*'] || ns2.nil? || ns2 == ['*']
107:         return ns2, true if ns1 == ['*']
108:         return ns1, true if ns2 == ['*']
109:         return ns1 || ns2, true
110:       end

[Validate]