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
- FINAL_SELECTORS =
Some psuedo-class-syntax selectors (
:after
and `:before) are actually considered pseudo-elements and must be at the end of the selector to function properly. %w[after before]
Instance Attribute Summary collapse
-
#arg ⇒ Array<String, Sass::Script::Node>?
readonly
The argument to the selector, or
nil
if no argument was given. -
#name ⇒ Array<String, Sass::Script::Node>
readonly
The name of the selector.
-
#type ⇒ Symbol
readonly
The type of the selector.
Attributes inherited from Simple
Instance Method Summary collapse
- #final? ⇒ Boolean
-
#initialize(type, name, arg) ⇒ Pseudo
constructor
A new instance of Pseudo.
- #specificity
- #to_a
-
#unify(sels)
Returns
nil
if this is a pseudoelement selector andsels
contains a pseudoelement selector different than this one.
Methods inherited from Simple
#eql?, #hash, #inspect, #to_s, #unify_namespaces
Constructor Details
#initialize(type, name, arg) ⇒ Pseudo
Returns a new instance of Pseudo.
382 383 384 385 386 |
# File 'lib/sass/selector.rb', line 382
def initialize(type, name, arg)
@type = type
@name = name
@arg = arg
end
|
Instance Attribute Details
#arg ⇒ Array<String, Sass::Script::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.
376 377 378 |
# File 'lib/sass/selector.rb', line 376
def arg
@arg
end
|
#name ⇒ Array<String, Sass::Script::Node> (readonly)
The name of the selector.
366 367 368 |
# File 'lib/sass/selector.rb', line 366
def name
@name
end
|
#type ⇒ Symbol (readonly)
The type of the selector.
:class
if this is a pseudoclass selector,
:element
if it's a pseudoelement.
354 355 356 |
# File 'lib/sass/selector.rb', line 354
def type
@type
end
|
Instance Method Details
#final? ⇒ Boolean
388 389 390 |
# File 'lib/sass/selector.rb', line 388
def final?
type == :class && FINAL_SELECTORS.include?(name.first)
end
|
#specificity
413 414 415 |
# File 'lib/sass/selector.rb', line 413
def specificity
type == :class ? SPECIFICITY_BASE : 1
end
|
#to_a
393 394 395 396 397 |
# File 'lib/sass/selector.rb', line 393
def to_a
res = [@type == :class ? ":" : "::"] + @name
(res << "(").concat(Sass::Util.strip_string_array(@arg)) << ")" if @arg
res
end
|
#unify(sels)
Returns nil
if this is a pseudoelement selector
and sels
contains a pseudoelement selector different than this one.
403 404 405 406 407 408 409 410 |
# File 'lib/sass/selector.rb', line 403
def unify(sels)
return if type == :element && sels.any? do |sel|
sel.is_a?(Pseudo) && sel.type == :element &&
(sel.name != self.name || sel.arg != self.arg)
end
return sels + [self] if final?
super
end
|