Class: Sass::Selector::Sequence
- Inherits:
-
AbstractSequence
- Object
- AbstractSequence
- Sass::Selector::Sequence
- Defined in:
- lib/sass/selector/sequence.rb
Overview
An operator-separated sequence of simple selector sequences.
Instance Attribute Summary collapse
-
#members ⇒ Array<SimpleSequence, String|Array<Sass::Tree::Node, String>>
readonly
The array of simple selector sequences, operators, and newlines.
Attributes inherited from AbstractSequence
Instance Method Summary collapse
-
#add_sources!(sources)
Add to the Sass::Selector::SimpleSequence#sources sets of the child simple sequences.
-
#do_extend(extends, parent_directives) ⇒ Array<Sequence>
Non-destructively extends this selector with the extensions specified in a hash (which should come from Tree::Visitors::Cssize).
-
#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). -
#initialize(seqs_and_ops) ⇒ Sequence
constructor
A new instance of Sequence.
-
#inspect ⇒ String
Returns a string representation of the sequence.
-
#line=(line) ⇒ Fixnum
Sets the line of the Sass template on which this selector was declared.
-
#resolve_parent_refs(super_seq) ⇒ Sequence
Resolves the Parent selectors within this selector by replacing them with the given parent selector, handling commas appropriately.
-
#superselector?(sseq) ⇒ Boolean
Returns whether or not this selector matches all elements that the given selector matches (as well as possibly more).
- #to_a
Methods inherited from AbstractSequence
#_specificity, #eql?, #has_placeholder?, #hash, #specificity, #to_s
Constructor Details
#initialize(seqs_and_ops) ⇒ Sequence
Returns a new instance of Sequence.
37 38 39 |
# File 'lib/sass/selector/sequence.rb', line 37
def initialize(seqs_and_ops)
@members = seqs_and_ops
end
|
Instance Attribute Details
#members ⇒ Array<SimpleSequence, String|Array<Sass::Tree::Node, String>> (readonly)
The array of simple selector sequences, operators, and
newlines. The operators are strings such as "+"
and ">"
representing
the corresponding CSS operators, or interpolated SassScript. Newlines
are also newline strings; these aren't semantically relevant, but they
do affect formatting.
34 35 36 |
# File 'lib/sass/selector/sequence.rb', line 34
def members
@members
end
|
Instance Method Details
#add_sources!(sources)
Add to the Sass::Selector::SimpleSequence#sources sets of the child simple sequences. This destructively modifies this sequence's members array, but not the child simple sequences.
125 126 127 |
# File 'lib/sass/selector/sequence.rb', line 125
def add_sources!(sources)
members.map! {|m| m.is_a?(SimpleSequence) ? m.with_more_sources(sources) : m}
end
|
#do_extend(extends, parent_directives) ⇒ Array<Sequence>
Non-destructively extends this selector with the extensions specified in a hash (which should come from Tree::Visitors::Cssize).
The extensions to perform on this selector
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/sass/selector/sequence.rb', line 80
def do_extend(extends, parent_directives, seen = Set.new)
extended_not_expanded = members.map do |sseq_or_op|
next [[sseq_or_op]] unless sseq_or_op.is_a?(SimpleSequence)
extended = sseq_or_op.do_extend(extends, parent_directives, seen)
choices = extended.map {|seq| seq.members}
choices.unshift([sseq_or_op]) unless extended.any? {|seq| seq.superselector?(sseq_or_op)}
choices
end
weaves = Sass::Util.paths(extended_not_expanded).map {|path| weave(path)}
Sass::Util.flatten(trim(weaves), 1).map {|p| Sequence.new(p)}
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.
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
|
#inspect ⇒ String
Returns a string representation of the sequence. This is basically the selector string.
116 117 118 |
# File 'lib/sass/selector/sequence.rb', line 116
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.
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.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/sass/selector/sequence.rb', line 48
def resolve_parent_refs(super_seq)
members = @members.dup
nl = (members.first == "\n" && members.shift)
unless members.any? do |seq_or_op|
seq_or_op.is_a?(SimpleSequence) && seq_or_op.members.first.is_a?(Parent)
end
old_members, members = members, []
members << nl if nl
members << SimpleSequence.new([Parent.new], false)
members += old_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).
101 102 103 104 |
# File 'lib/sass/selector/sequence.rb', line 101
def superselector?(sseq)
return false unless members.size == 1
members.last.superselector?(sseq)
end
|
#to_a
107 108 109 110 |
# File 'lib/sass/selector/sequence.rb', line 107
def to_a
ary = @members.map {|seq_or_op| seq_or_op.is_a?(SimpleSequence) ? seq_or_op.to_a : seq_or_op}
Sass::Util.intersperse(ary, " ").flatten.compact
end
|