Class: Sass::Selector::CommaSequence

Inherits:
AbstractSequence show all
Defined in:
lib/sass/selector/comma_sequence.rb

Overview

A comma-separated sequence of selectors.

Instance Attribute Summary collapse

Attributes inherited from AbstractSequence

#filename, #line

Instance Method Summary collapse

Constructor Details

#initialize(seqs) ⇒ CommaSequence

Returns a new instance of CommaSequence.

Parameters:



12
13
14
# File 'lib/sass/selector/comma_sequence.rb', line 12

def initialize(seqs)
  @members = seqs
end

Instance Attribute Details

#membersArray<Sequence> (readonly)

The comma-separated selector sequences represented by this class.

Returns:



9
10
11
# File 'lib/sass/selector/comma_sequence.rb', line 9

def members
  @members
end

Instance Method Details

#do_extend(extends) ⇒ CommaSequence

TODO:

Link this to the reference documentation on @extend when such a thing exists.

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

Parameters:

Returns:

  • (CommaSequence)

    A copy of this selector, with extensions made according to extends



52
53
54
# File 'lib/sass/selector/comma_sequence.rb', line 52

def do_extend(extends)
  CommaSequence.new(members.map {|seq| seq.do_extend(extends)}.flatten)
end

#eql?(other) ⇒ Boolean

Checks equality between this and another object.

Parameters:

  • other (Object)

    The object to test equality against

Returns:

  • (Boolean)

    Whether or not this is equal to other



75
76
77
# File 'lib/sass/selector/comma_sequence.rb', line 75

def eql?(other)
  other.class == self.class && other.members.eql?(self.members)
end

#hashFixnum

Returns a hash code for this sequence.

Returns:

  • (Fixnum)


67
68
69
# File 'lib/sass/selector/comma_sequence.rb', line 67

def hash
  members.hash
end

#inspectString

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

Returns:

  • (String)


60
61
62
# File 'lib/sass/selector/comma_sequence.rb', line 60

def inspect
  members.map {|m| m.inspect}.join(", ")
end

#resolve_parent_refs(super_cseq) ⇒ CommaSequence

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

Parameters:

Returns:

  • (CommaSequence)

    This selector, with parent references resolved

Raises:



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/sass/selector/comma_sequence.rb', line 23

def resolve_parent_refs(super_cseq)
  if super_cseq.nil?
    if @members.any? do |sel|
        sel.members.any? do |sel_or_op|
          sel_or_op.is_a?(SimpleSequence) && sel_or_op.members.any? {|ssel| ssel.is_a?(Parent)}
        end
      end
      raise Sass::SyntaxError.new("Base-level rules cannot contain the parent-selector-referencing character '&'.")
    end
    return self
  end

  CommaSequence.new(
    super_cseq.members.map do |super_seq|
      @members.map {|seq| seq.resolve_parent_refs(super_seq)}
    end.flatten)
end