Class: Sass::Selector::Sequence
- Inherits:
- AbstractSequence
- Object
- AbstractSequence
- Sass::Selector::Sequence
- Defined in:
- /Users/ceppstei/Projects/sass-lang/.sass/lib/sass/selector/sequence.rb
Overview
An operator-separated sequence of simple selector sequences.
Instance Attribute Summary (collapse)
- - (Array<SimpleSequence, String|Array<Sass::Tree::Node, String>>) members 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.
- - (Boolean) contains_parent_ref?
Returns whether there’s a Parent selector anywhere in this sequence.
- - (Array<Sequence>) do_extend(extends, parent_directives, replace, seen, original)
Non-destructively extends this selector with the extensions specified in a hash (which should come from Tree::Visitors::Cssize).
- - (String?) filename=(filename)
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). - - (Sequence) initialize(seqs_and_ops) constructor
A new instance of Sequence.
- - (String) inspect
Returns a string representation of the sequence.
- - (Fixnum) line=(line)
Sets the line of the Sass template on which this selector was declared.
- - (CommaSequence) resolve_parent_refs(super_cseq, implicit_parent)
Resolves the Parent selectors within this selector by replacing them with the given parent selector, handling commas appropriately.
- - subjectless
Converts the subject operator “!”, if it exists, into a “:has()” selector.
- - (Boolean) superselector?(seq)
Returns whether or not this selector matches all elements that the given selector matches (as well as possibly more).
- - to_s(opts = {})
- - (CommaSequence?) unify(other)
Unifies this with another selector sequence to produce a selector that matches (a subset of) the intersection of the two inputs.
Methods inherited from AbstractSequence
#_specificity, #eql?, #has_placeholder?, #hash, #specificity
Constructor Details
- (Sequence) initialize(seqs_and_ops)
Returns a new instance of Sequence
38 39 40 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/selector/sequence.rb', line 38
def initialize(seqs_and_ops)
@members = seqs_and_ops
end |
Instance Attribute Details
- (Array<SimpleSequence, String|Array<Sass::Tree::Node, String>>) members (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 '/Users/ceppstei/Projects/sass-lang/.sass/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.
177 178 179 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/selector/sequence.rb', line 177
def add_sources!(sources)
members.map! {|m| m.is_a?(SimpleSequence) ? m.with_more_sources(sources) : m}
end |
- (Boolean) contains_parent_ref?
Returns whether there’s a Parent selector anywhere in this sequence.
79 80 81 82 83 84 85 86 87 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/selector/sequence.rb', line 79
def contains_parent_ref?
members.any? do |sseq_or_op|
next false unless sseq_or_op.is_a?(SimpleSequence)
next true if sseq_or_op.members.first.is_a?(Parent)
sseq_or_op.members.any? do |sel|
sel.is_a?(Pseudo) && sel.selector && sel.selector.contains_parent_ref?
end
end
end |
- (Array<Sequence>) do_extend(extends, parent_directives, replace, seen, original)
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
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/selector/sequence.rb', line 109
def do_extend(extends, parent_directives, replace, seen, original)
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, replace, seen)
# The First Law of Extend says that the generated selector should have
# specificity greater than or equal to that of the original selector.
# In order to ensure that, we record the original selector's
# (`extended.first`) original specificity.
extended.first.add_sources!([self]) if original && !has_placeholder?
extended.map {|seq| seq.members}
end
weaves = Sass::Util.paths(extended_not_expanded).map {|path| weave(path)}
trim(weaves).map {|p| Sequence.new(p)}
end |
- (String?) filename=(filename)
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 '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/selector/sequence.rb', line 22
def filename=(filename)
members.each {|m| m.filename = filename if m.is_a?(SimpleSequence)}
filename
end |
- (String) inspect
Returns a string representation of the sequence. This is basically the selector string.
168 169 170 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/selector/sequence.rb', line 168
def inspect
members.map {|m| m.inspect}.join(" ")
end |
- (Fixnum) line=(line)
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 '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/selector/sequence.rb', line 11
def line=(line)
members.each {|m| m.line = line if m.is_a?(SimpleSequence)}
@line = line
end |
- (CommaSequence) resolve_parent_refs(super_cseq, implicit_parent)
Resolves the Parent selectors within this selector by replacing them with the given parent selector, handling commas appropriately.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/selector/sequence.rb', line 52
def resolve_parent_refs(super_cseq, implicit_parent)
members = @members.dup
nl = (members.first == "\n" && members.shift)
contains_parent_ref = contains_parent_ref?
return CommaSequence.new([self]) if !implicit_parent && !contains_parent_ref
unless contains_parent_ref
old_members, members = members, []
members << nl if nl
members << SimpleSequence.new([Parent.new], false)
members += old_members
end
CommaSequence.new(Sass::Util.paths(members.map do |sseq_or_op|
next [sseq_or_op] unless sseq_or_op.is_a?(SimpleSequence)
sseq_or_op.resolve_parent_refs(super_cseq).members
end).map do |path|
Sequence.new(path.map do |seq_or_op|
next seq_or_op unless seq_or_op.is_a?(Sequence)
seq_or_op.members
end.flatten)
end)
end |
- subjectless
Converts the subject operator “!”, if it exists, into a “:has()” selector.
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/selector/sequence.rb', line 185
def subjectless
pre_subject = []
has = []
subject = nil
members.each do |sseq_or_op|
if subject
has << sseq_or_op
elsif sseq_or_op.is_a?(String) || !sseq_or_op.subject?
pre_subject << sseq_or_op
else
subject = sseq_or_op.dup
subject.members = sseq_or_op.members.dup
subject.subject = false
has = []
end
end
return self unless subject
unless has.empty?
subject.members << Pseudo.new(:class, 'has', nil, CommaSequence.new([Sequence.new(has)]))
end
Sequence.new(pre_subject + [subject])
end |
- (Boolean) superselector?(seq)
Returns whether or not this selector matches all elements that the given selector matches (as well as possibly more).
155 156 157 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/selector/sequence.rb', line 155
def superselector?(seq)
_superselector?(members, seq.members)
end |
- to_s(opts = {})
160 161 162 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/selector/sequence.rb', line 160
def to_s(opts = {})
@members.map {|m| m.is_a?(String) ? m : m.to_s(opts)}.join(" ").gsub(/ ?\n ?/, "\n")
end |
- (CommaSequence?) unify(other)
Unifies this with another selector sequence to produce a selector that matches (a subset of) the intersection of the two inputs.
137 138 139 140 141 142 143 144 145 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/selector/sequence.rb', line 137
def unify(other)
base = members.last
other_base = other.members.last
return unless base.is_a?(SimpleSequence) && other_base.is_a?(SimpleSequence)
return unless (unified = other_base.unify(base))
woven = weave([members[0...-1], other.members[0...-1] + [unified]])
CommaSequence.new(woven.map {|w| Sequence.new(w)})
end |