Class: Sass::Selector::Pseudo
Overview
A pseudoclass (e.g. :visited
) or pseudoelement (e.g. ::first-line
) selector.
It can have arguments (e.g. :nth-child(2n+1)
).
Constant Summary collapse
- ACTUALLY_ELEMENTS =
Some psuedo-class-syntax selectors are actually considered pseudo-elements and must be treated differently. This is a list of such selectors
%w[after before first-line first-letter]
Instance Attribute Summary collapse
-
#arg ⇒ Array<String, Sass::Script::Tree::Node>?
readonly
The argument to the selector, or
nil
if no argument was given. -
#name ⇒ Array<String, Sass::Script::Tree::Node>
readonly
The name of the selector.
-
#syntactic_type ⇒ Symbol
readonly
Like #type, but returns the type of selector this looks like, rather than the type it is semantically.
Attributes inherited from Simple
Instance Method Summary collapse
-
#initialize(type, name, arg) ⇒ Pseudo
constructor
A new instance of Pseudo.
- #specificity
- #to_a
-
#type ⇒ Symbol
The type of the selector.
-
#unify(sels)
Returns
nil
if this is a pseudoelement selector andsels
contains a pseudoelement selector different than this one.
Methods inherited from Simple
#eql?, #equality_key, #hash, #inspect, #to_s, #unify_namespaces
Constructor Details
#initialize(type, name, arg) ⇒ Pseudo
Returns a new instance of Pseudo.
393 394 395 396 397 |
# File 'lib/sass/selector.rb', line 393
def initialize(type, name, arg)
@syntactic_type = type
@name = name
@arg = arg
end
|
Instance Attribute Details
#arg ⇒ Array<String, Sass::Script::Tree::Node>? (readonly)
The argument to the selector,
or nil
if no argument was given.
This may include SassScript nodes that will be run during resolution. Note that this should not include SassScript nodes after resolution has taken place.
387 388 389 |
# File 'lib/sass/selector.rb', line 387
def arg
@arg
end
|
#name ⇒ Array<String, Sass::Script::Tree::Node> (readonly)
The name of the selector.
377 378 379 |
# File 'lib/sass/selector.rb', line 377
def name
@name
end
|
#syntactic_type ⇒ Symbol (readonly)
Like #type, but returns the type of selector this looks like, rather than the type it is semantically. This only differs from type for selectors in ACTUALLY_ELEMENTS.
372 373 374 |
# File 'lib/sass/selector.rb', line 372
def syntactic_type
@syntactic_type
end
|
Instance Method Details
#specificity
427 428 429 |
# File 'lib/sass/selector.rb', line 427
def specificity
type == :class ? SPECIFICITY_BASE : 1
end
|
#to_a
408 409 410 411 412 |
# File 'lib/sass/selector.rb', line 408
def to_a
res = [syntactic_type == :class ? ":" : "::"] + @name
(res << "(").concat(Sass::Util.strip_string_array(@arg)) << ")" if @arg
res
end
|
#type ⇒ Symbol
The type of the selector. :class
if this is a pseudoclass selector,
:element
if it's a pseudoelement.
403 404 405 |
# File 'lib/sass/selector.rb', line 403
def type
ACTUALLY_ELEMENTS.include?(name.first) ? :element : syntactic_type
end
|
#unify(sels)
Returns nil
if this is a pseudoelement selector
and sels
contains a pseudoelement selector different than this one.
418 419 420 421 422 423 424 |
# File 'lib/sass/selector.rb', line 418
def unify(sels)
return if type == :element && sels.any? do |sel|
sel.is_a?(Pseudo) && sel.type == :element &&
(sel.name != name || sel.arg != arg)
end
super
end
|