Class: Sass::Selector::Simple
- Inherits:
-
Object
- Object
- Sass::Selector::Simple
- Defined in:
- 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, Interpolation, Negation, Parent, Pseudo, Universal
Instance Attribute Summary collapse
-
#filename ⇒ String?
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). -
#line ⇒ Fixnum
The line of the Sass template on which this selector was declared.
Instance Method Summary collapse
-
#eql?(other) ⇒ Boolean
Checks equality between this and another object.
-
#hash ⇒ Fixnum
Returns a hash code for this selector object.
-
#inspect ⇒ String
Returns a string representation of the node.
-
#to_a ⇒ Array<String, Sass::Script::Node>
Returns a representation of the node as an array of strings and potentially Sass::Script::Nodes (if there's interpolation in the selector).
-
#unify(sels) ⇒ Array<Simple>?
Unifies this selector with a SimpleSequence's members array, returning another
SimpleSequence
members array that matches both this selector and the input selector. -
#unify_namespaces(ns1, ns2) ⇒ Array(String or nil, Boolean)
protected
Unifies two namespaces, returning a namespace that works for both of them if possible.
Instance Attribute Details
#filename ⇒ String?
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).
15 16 17 |
# File 'lib/sass/selector/simple.rb', line 15
def filename
@filename
end
|
#line ⇒ Fixnum
The line of the Sass template on which this selector was declared.
9 10 11 |
# File 'lib/sass/selector/simple.rb', line 9
def line
@line
end
|
Instance Method Details
#eql?(other) ⇒ Boolean
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.
55 56 57 |
# File 'lib/sass/selector/simple.rb', line 55
def eql?(other)
other.class == self.class && other.to_a.eql?(to_a)
end
|
#hash ⇒ Fixnum
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.
43 44 45 |
# File 'lib/sass/selector/simple.rb', line 43
def hash
to_a.hash
end
|
#inspect ⇒ String
Returns a string representation of the node. This is basically the selector string.
32 33 34 |
# File 'lib/sass/selector/simple.rb', line 32
def inspect
to_a.map {|e| e.is_a?(Sass::Script::Node) ? "\#{#{e.to_sass}}" : e}.join
end
|
#to_a ⇒ Array<String, Sass::Script::Node>
Returns a representation of the node as an array of strings and potentially Sass::Script::Nodes (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.
24 25 26 |
# File 'lib/sass/selector/simple.rb', line 24
def to_a
raise NotImplementedError.new("All subclasses of Sass::Selector::Simple must override #to_a.")
end
|
#unify(sels) ⇒ Array<Simple>?
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).
76 77 78 79 80 81 82 |
# File 'lib/sass/selector/simple.rb', line 76
def unify(sels)
return sels if sels.any? {|sel2| eql?(sel2)}
if sels.last.is_a?(Pseudo) && sels.last.type == :element
return sels[0...-1] + [self, sels.last]
end
sels + [self]
end
|
#unify_namespaces(ns1, ns2) ⇒ Array(String or nil, Boolean) (protected)
Unifies two namespaces, returning a namespace that works for both of them if possible.
99 100 101 102 103 104 |
# File 'lib/sass/selector/simple.rb', line 99
def unify_namespaces(ns1, ns2)
return nil, false unless ns1 == ns2 || ns1.nil? || ns1 == ['*'] || ns2.nil? || ns2 == ['*']
return ns2, true if ns1 == ['*']
return ns1, true if ns2 == ['*']
return ns1 || ns2, true
end
|