Class: Sass::Selector::Simple

Inherits:
Object
  • Object
show all
Defined in:
/home/nweiz/code/sass-site/.sass/lib/sass/selector/simple.rb

Overview

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

Direct Known Subclasses

Attribute, Class, Element, Id, Parent, Placeholder, Pseudo, Universal

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (String?) filename

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).

Returns:

  • (String, nil)


15
16
17
# File '/home/nweiz/code/sass-site/.sass/lib/sass/selector/simple.rb', line 15

def filename
  @filename
end

- (Integer) line

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

Returns:

  • (Integer)


9
10
11
# File '/home/nweiz/code/sass-site/.sass/lib/sass/selector/simple.rb', line 9

def line
  @line
end

Instance Method Details

- (Boolean) eql?(other) Also known as: ==

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.

Parameters:

  • other (Object)

    The object to test equality against

Returns:

  • (Boolean)

    Whether or not this is equal to other



60
61
62
# File '/home/nweiz/code/sass-site/.sass/lib/sass/selector/simple.rb', line 60

def eql?(other)
  other.class == self.class && other.hash == hash && other.equality_key == equality_key
end

- (String) equality_key (protected)

Returns the key used for testing whether selectors are equal.

This is a cached version of #to_s.

Returns:

  • (String)


99
100
101
# File '/home/nweiz/code/sass-site/.sass/lib/sass/selector/simple.rb', line 99

def equality_key
  @equality_key ||= to_s
end

- (Integer) hash

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.

Returns:

  • (Integer)


48
49
50
# File '/home/nweiz/code/sass-site/.sass/lib/sass/selector/simple.rb', line 48

def hash
  @_hash ||= equality_key.hash
end

- (String) inspect

Returns:

  • (String)

See Also:



28
29
30
# File '/home/nweiz/code/sass-site/.sass/lib/sass/selector/simple.rb', line 28

def inspect
  to_s
end

- (String) to_s(opts = {})

Returns the selector string.

Parameters:

  • opts (Hash) (defaults to: {})

    rendering options.

Options Hash (opts):

  • :style (Symbol)

    The css rendering style.

Returns:

  • (String)


37
38
39
# File '/home/nweiz/code/sass-site/.sass/lib/sass/selector/simple.rb', line 37

def to_s(opts = {})
  Sass::Util.abstract(self)
end

- (Array<Simple>?) unify(sels)

Unifies this selector with a Sass::Selector::SimpleSequence's 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).

Parameters:

Returns:

Raises:

  • (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



82
83
84
85
86
87
88
89
90
# File '/home/nweiz/code/sass-site/.sass/lib/sass/selector/simple.rb', line 82

def unify(sels)
  return sels.first.unify([self]) if sels.length == 1 && sels.first.is_a?(Universal)
  return sels if sels.any? {|sel2| eql?(sel2)}
  if !is_a?(Pseudo) || (sels.last.is_a?(Pseudo) && sels.last.type == :element)
    _, i = sels.each_with_index.find {|sel, _| sel.is_a?(Pseudo)}
  end
  return sels + [self] unless i
  sels[0...i] + [self] + sels[i..-1]
end

- (Array(String or nil, Boolean)) unify_namespaces(ns1, ns2) (protected)

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

Parameters:

  • 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.

  • ns2 (String, nil)

    The second namespace. See ns1.

Returns:

  • (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.



116
117
118
119
120
121
# File '/home/nweiz/code/sass-site/.sass/lib/sass/selector/simple.rb', line 116

def unify_namespaces(ns1, ns2)
  return ns2, true if ns1 == '*'
  return ns1, true if ns2 == '*'
  return nil, false unless ns1 == ns2
  [ns1, true]
end

- (Boolean) unique?

Whether only one instance of this simple selector is allowed in a given complex selector.

Returns:

  • (Boolean)


21
22
23
# File '/home/nweiz/code/sass-site/.sass/lib/sass/selector/simple.rb', line 21

def unique?
  false
end