Class Index [+]

Quicksearch

Sass::Selector::SimpleSequence

A unseparated sequence of selectors that all apply to a single element. For example, `.foo#[attr=baz]` is a simple sequence of the selectors `.foo`, `#`, and `[attr=baz]`.

Attributes

members[R]

The array of individual selectors.

@return [Array]

Public Class Methods

new(selectors) click to toggle source

@param selectors [Array] See {#members}

    # File lib/sass/selector/simple_sequence.rb, line 29
29:       def initialize(selectors)
30:         @members = selectors
31:       end

Public Instance Methods

base() click to toggle source

Returns the element or universal selector in this sequence, if it exists.

@return [Element, Universal, nil]

    # File lib/sass/selector/simple_sequence.rb, line 17
17:       def base
18:         @base ||= (members.first if members.first.is_a?(Element) || members.first.is_a?(Universal))
19:       end
do_extend(extends, seen = Set.new) click to toggle source

Non-destrucively extends this selector with the extensions specified in a hash (which should be populated via {Sass::Tree::Node#cssize}).

@overload def do_extend(extends) @param extends [{Selector::Simple => Selector::Sequence}]

  The extensions to perform on this selector

@return [Array] A list of selectors generated

  by extending this selector with `extends`.

@see CommaSequence#do_extend

    # File lib/sass/selector/simple_sequence.rb, line 64
64:       def do_extend(extends, seen = Set.new)
65:         extends.get(members.to_set).map do |seq, sels|
66:           # If A {@extend B} and C {...},
67:           # seq is A, sels is B, and self is C
68: 
69:           self_without_sel = self.members - sels
70:           next unless unified = seq.members.last.unify(self_without_sel)
71:           [sels, seq.members[0...1] + [unified]]
72:         end.compact.map do |sels, seq|
73:           seq = Sequence.new(seq)
74:           seen.include?(sels) ? [] : seq.do_extend(extends, seen + [sels])
75:         end.flatten.uniq
76:       end
inspect() click to toggle source

Returns a string representation of the sequence. This is basically the selector string.

@return [String]

     # File lib/sass/selector/simple_sequence.rb, line 121
121:       def inspect
122:         members.map {|m| m.inspect}.join
123:       end
resolve_parent_refs(super_seq) click to toggle source

Resolves the {Parent} selectors within this selector by replacing them with the given parent selector, handling commas appropriately.

@param super_seq [Sequence] The parent selector sequence @return [Array] This selector, with parent references resolved.

  This is an array because the parent selector is itself a {Sequence}

@raise [Sass::SyntaxError] If a parent selector is invalid

    # File lib/sass/selector/simple_sequence.rb, line 41
41:       def resolve_parent_refs(super_seq)
42:         # Parent selector only appears as the first selector in the sequence
43:         return [self] unless @members.first.is_a?(Parent)
44: 
45:         return super_seq.members if @members.size == 1
46:         unless super_seq.members.last.is_a?(SimpleSequence)
47:           raise Sass::SyntaxError.new("Invalid parent selector: " + super_seq.to_a.join)
48:         end
49: 
50:         super_seq.members[0...1] +
51:           [SimpleSequence.new(super_seq.members.last.members + @members[1..1])]
52:       end
rest() click to toggle source

Returns the non-base selectors in this sequence.

@return [Set]

    # File lib/sass/selector/simple_sequence.rb, line 24
24:       def rest
25:         @rest ||= Set.new(base ? members[1..1] : members)
26:       end
superselector?(sseq) click to toggle source

Returns whether or not this selector matches all elements that the given selector matches (as well as possibly more).

@example (.foo).superselector?(.foo.bar) #=> true (.foo).superselector?(.bar) #=> false

@param sseq [SimpleSequence] @return [Boolean]

     # File lib/sass/selector/simple_sequence.rb, line 108
108:       def superselector?(sseq)
109:         (base.nil? || base.eql?(sseq.base)) && rest.subset?(sseq.rest)
110:       end
to_a() click to toggle source

@see Simple#to_a

     # File lib/sass/selector/simple_sequence.rb, line 113
113:       def to_a
114:         @members.map {|sel| sel.to_a}.flatten
115:       end
unify(sels) click to toggle source

Unifies this selector with another {SimpleSequence}’s {SimpleSequence#members members array}, returning another `SimpleSequence` that matches both this selector and the input selector.

@param sels [Array] A {SimpleSequence}’s {SimpleSequence#members members array} @return [SimpleSequence, nil] A {SimpleSequence} matching both `sels` and this selector,

  or `nil` if this is impossible (e.g. unifying `#foo` and `#bar`)

@raise [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
    # File lib/sass/selector/simple_sequence.rb, line 91
91:       def unify(sels)
92:         return unless sseq = members.inject(sels) do |sseq, sel|
93:           return unless sseq
94:           sel.unify(sseq)
95:         end
96:         SimpleSequence.new(sseq)
97:       end

Private Instance Methods

_eql?(other) click to toggle source
     # File lib/sass/selector/simple_sequence.rb, line 131
131:       def _eql?(other)
132:         other.base.eql?(self.base) && Haml::Util.set_eql?(other.rest, self.rest)
133:       end
_hash() click to toggle source
     # File lib/sass/selector/simple_sequence.rb, line 127
127:       def _hash
128:         [base, Haml::Util.set_hash(rest)].hash
129:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.