Class: Sass::Selector::Sequence

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

Overview

An operator-separated sequence of simple selector sequences.

Instance Attribute Summary collapse

Attributes inherited from AbstractSequence

#filename, #line

Instance Method Summary collapse

Constructor Details

#initialize(seqs_and_ops) ⇒ Sequence

Returns a new instance of Sequence.

Parameters:



38
39
40
# File 'lib/sass/selector/sequence.rb', line 38

def initialize(seqs_and_ops)
  @members = seqs_and_ops
end

Instance Attribute Details

#membersArray<SimpleSequence, String> (readonly)

The array of simple selector sequences, operators, and newlines. The operators are strings such as "+" and ">" representing the corresponding CSS operators. Newlines are also newline strings; these aren't semantically relevant, but they do affect formatting.

Returns:



35
36
37
# File 'lib/sass/selector/sequence.rb', line 35

def members
  @members
end

Instance Method Details

#do_extend(extends) ⇒ Array<Sequence>

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

Parameters:

Returns:

See Also:



79
80
81
82
83
84
85
86
87
88
# File 'lib/sass/selector/sequence.rb', line 79

def do_extend(extends, seen = Set.new)
  paths = Haml::Util.paths(members.map do |sseq_or_op|
      next [[sseq_or_op]] unless sseq_or_op.is_a?(SimpleSequence)
      extended = sseq_or_op.do_extend(extends, seen)
      choices = extended.map {|seq| seq.members}
      choices.unshift([sseq_or_op]) unless extended.any? {|seq| seq.superselector?(sseq_or_op)}
      choices
    end)
  Haml::Util.flatten(paths.map {|path| weave(path)}, 1).map {|p| Sequence.new(p)}
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



132
133
134
135
# File 'lib/sass/selector/sequence.rb', line 132

def eql?(other)
  other.class == self.class &&
    other.members.reject {|m| m == "\n"}.eql?(self.members.reject {|m| m == "\n"})
end

#filename=(filename) ⇒ String?

Sets the name of the file in which this selector was declared, or nil if it was not declared in a file (e.g. on stdin). This also sets the filename for all child selectors.

Parameters:

  • filename (String, nil)

Returns:

  • (String, nil)


22
23
24
25
# File 'lib/sass/selector/sequence.rb', line 22

def filename=(filename)
  members.each {|m| m.filename = filename if m.is_a?(SimpleSequence)}
  filename
end

#hashFixnum

Returns a hash code for this sequence.

Returns:

  • (Fixnum)


124
125
126
# File 'lib/sass/selector/sequence.rb', line 124

def hash
  members.reject {|m| m == "\n"}.hash
end

#inspectString

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

Returns:

  • (String)


117
118
119
# File 'lib/sass/selector/sequence.rb', line 117

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

#line=(line) ⇒ Fixnum

Sets the line of the Sass template on which this selector was declared. This also sets the line for all child selectors.

Parameters:

  • line (Fixnum)

Returns:

  • (Fixnum)


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

def line=(line)
  members.each {|m| m.line = line if m.is_a?(SimpleSequence)}
  line
end

#resolve_parent_refs(super_seq) ⇒ Sequence

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

Parameters:

  • super_seq (Sequence)

    The parent selector sequence

Returns:

  • (Sequence)

    This selector, with parent references resolved

Raises:



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/sass/selector/sequence.rb', line 49

def resolve_parent_refs(super_seq)
  members = @members
  members.slice!(0) if nl = (members.first == "\n")
  unless members.any? do |seq_or_op|
      seq_or_op.is_a?(SimpleSequence) && seq_or_op.members.first.is_a?(Parent)
    end
    members = []
    members << "\n" if nl
    members << SimpleSequence.new([Parent.new])
    members += @members
  end

  Sequence.new(
    members.map do |seq_or_op|
      next seq_or_op unless seq_or_op.is_a?(SimpleSequence)
      seq_or_op.resolve_parent_refs(super_seq)
    end.flatten)
end

#superselector?(sseq) ⇒ Boolean

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

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

Parameters:

Returns:

  • (Boolean)


100
101
102
103
# File 'lib/sass/selector/sequence.rb', line 100

def superselector?(sseq)
  return false unless members.size == 1
  members.last.superselector?(sseq)
end

#to_a



106
107
108
109
110
111
# File 'lib/sass/selector/sequence.rb', line 106

def to_a
  ary = @members.map {|seq_or_op| seq_or_op.is_a?(SimpleSequence) ? seq_or_op.to_a : seq_or_op}
  ary = Haml::Util.intersperse(ary, " ")
  ary = Haml::Util.substitute(ary, [" ", "\n", " "], ["\n"])
  ary.flatten.compact
end