Class: Sass::Selector::Pseudo

Inherits:
Simple
  • Object
show all
Defined in:
lib/sass/selector.rb

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

Returns:

  • (Array<String>)
%w[after before first-line first-letter]

Instance Attribute Summary collapse

Attributes inherited from Simple

#filename, #line

Instance Method Summary collapse

Methods inherited from Simple

#eql?, #hash, #inspect, #to_s, #unify_namespaces

Constructor Details

#initialize(type, name, arg) ⇒ Pseudo

Returns a new instance of Pseudo.

Parameters:

  • type (Symbol)

    See #type

  • name (Array<String, Sass::Script::Node>)

    The name of the selector

  • arg (nil, Array<String, Sass::Script::Node>)

    The argument to the selector, or nil if no argument was given



382
383
384
385
386
# File 'lib/sass/selector.rb', line 382

def initialize(type, name, arg)
  @syntactic_type = type
  @name = name
  @arg = arg
end

Instance Attribute Details

#argArray<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.

Returns:



376
377
378
# File 'lib/sass/selector.rb', line 376

def arg
  @arg
end

#nameArray<String, Sass::Script::Node> (readonly)

The name of the selector.

Returns:



366
367
368
# File 'lib/sass/selector.rb', line 366

def name
  @name
end

#syntactic_typeSymbol (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.

Returns:

  • (Symbol)


361
362
363
# File 'lib/sass/selector.rb', line 361

def syntactic_type
  @syntactic_type
end

Instance Method Details

#specificity



416
417
418
# File 'lib/sass/selector.rb', line 416

def specificity
  type == :class ? SPECIFICITY_BASE : 1
end

#to_a

See Also:

  • Selector#to_a


397
398
399
400
401
# File 'lib/sass/selector.rb', line 397

def to_a
  res = [syntactic_type == :class ? ":" : "::"] + @name
  (res << "(").concat(Sass::Util.strip_string_array(@arg)) << ")" if @arg
  res
end

#typeSymbol

The type of the selector. :class if this is a pseudoclass selector, :element if it's a pseudoelement.

Returns:

  • (Symbol)


392
393
394
# File 'lib/sass/selector.rb', line 392

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.

See Also:

  • Selector#unify


407
408
409
410
411
412
413
# File 'lib/sass/selector.rb', line 407

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
  super
end