Class: Sass::Selector::CommaSequence
- Inherits:
- AbstractSequence
- Object
- AbstractSequence
- Sass::Selector::CommaSequence
- Defined in:
- /Users/ceppstei/Projects/sass-lang/.sass/lib/sass/selector/comma_sequence.rb
Overview
A comma-separated sequence of selectors.
Instance Attribute Summary (collapse)
- - (Array<Sequence>) members readonly
The comma-separated selector sequences represented by this class.
Attributes inherited from AbstractSequence
Instance Method Summary (collapse)
- - (Boolean) contains_parent_ref?
Returns whether there’s a Parent selector anywhere in this sequence.
- - (CommaSequence) do_extend(extends, parent_directives = [], replace = false, seen = Set.new, original = true)
Non-destrucively extends this selector with the extensions specified in a hash (which should come from Tree::Visitors::Cssize).
- - (CommaSequence) initialize(seqs) constructor
A new instance of CommaSequence.
- - (String) inspect
Returns a string representation of the sequence.
- - populate_extends(extends, extendee, extend_node = nil, parent_directives = [])
Populates a subset map that can then be used to extend selectors.
- - (CommaSequence) resolve_parent_refs(super_cseq, implicit_parent = true)
Resolves the Parent selectors within this selector by replacing them with the given parent selector, handling commas appropriately.
- - (Boolean) superselector?(cseq)
Returns whether or not this selector matches all elements that the given selector matches (as well as possibly more).
- - to_s(opts = {})
- - (Sass::Script::Value::List) to_sass_script
Returns a SassScript representation of this selector.
- - (CommaSequence?) unify(other)
Unifies this with another comma selector 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
- (CommaSequence) initialize(seqs)
Returns a new instance of CommaSequence
12 13 14 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/selector/comma_sequence.rb', line 12
def initialize(seqs)
@members = seqs
end |
Instance Attribute Details
- (Array<Sequence>) members (readonly)
The comma-separated selector sequences represented by this class.
9 10 11 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/selector/comma_sequence.rb', line 9
def members
@members
end |
Instance Method Details
- (Boolean) contains_parent_ref?
Returns whether there’s a Parent selector anywhere in this sequence.
43 44 45 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/selector/comma_sequence.rb', line 43
def contains_parent_ref?
@members.any? {|sel| sel.contains_parent_ref?}
end |
- (CommaSequence) do_extend(extends, parent_directives = [], replace = false, seen = Set.new, original = true)
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 come from Tree::Visitors::Cssize).
The extensions to perform on this selector
68 69 70 71 72 73 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/selector/comma_sequence.rb', line 68
def do_extend(extends, parent_directives = [], replace = false, seen = Set.new,
original = true)
CommaSequence.new(members.map do |seq|
seq.do_extend(extends, parent_directives, replace, seen, original)
end.flatten)
end |
- (String) inspect
Returns a string representation of the sequence. This is basically the selector string.
157 158 159 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/selector/comma_sequence.rb', line 157
def inspect
members.map {|m| m.inspect}.join(", ")
end |
- populate_extends(extends, extendee, extend_node = nil, parent_directives = [])
Populates a subset map that can then be used to extend selectors. This registers an extension with this selector as the extender and extendee
as the extendee.
The subset map representing the extensions to perform.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/selector/comma_sequence.rb', line 100
def populate_extends(extends, extendee, extend_node = nil, parent_directives = [])
extendee.members.each do |seq|
if seq.members.size > 1
raise Sass::SyntaxError.new("Can't extend #{seq}: can't extend nested selectors")
end
sseq = seq.members.first
if !sseq.is_a?(Sass::Selector::SimpleSequence)
raise Sass::SyntaxError.new("Can't extend #{seq}: invalid selector")
elsif sseq.members.any? {|ss| ss.is_a?(Sass::Selector::Parent)}
raise Sass::SyntaxError.new("Can't extend #{seq}: can't extend parent selectors")
end
sel = sseq.members
members.each do |member|
unless member.members.last.is_a?(Sass::Selector::SimpleSequence)
raise Sass::SyntaxError.new("#{member} can't extend: invalid selector")
end
extends[sel] = Sass::Tree::Visitors::Cssize::Extend.new(
member, sel, extend_node, parent_directives, :not_found)
end
end
end |
- (CommaSequence) resolve_parent_refs(super_cseq, implicit_parent = true)
Resolves the Parent selectors within this selector by replacing them with the given parent selector, handling commas appropriately.
26 27 28 29 30 31 32 33 34 35 36 37 38 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/selector/comma_sequence.rb', line 26
def resolve_parent_refs(super_cseq, implicit_parent = true)
if super_cseq.nil?
if contains_parent_ref?
raise Sass::SyntaxError.new(
"Base-level rules cannot contain the parent-selector-referencing character '&'.")
end
return self
end
CommaSequence.new(Sass::Util.flatten_vertically(@members.map do |seq|
seq.resolve_parent_refs(super_cseq, implicit_parent).members
end))
end |
- (Boolean) superselector?(cseq)
Returns whether or not this selector matches all elements that the given selector matches (as well as possibly more).
83 84 85 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/selector/comma_sequence.rb', line 83
def superselector?(cseq)
cseq.members.all? {|seq1| members.any? {|seq2| seq2.superselector?(seq1)}}
end |
- to_s(opts = {})
162 163 164 165 166 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/selector/comma_sequence.rb', line 162
def to_s(opts = {})
@members.map {|m| m.to_s(opts)}.
join(opts[:style] == :compressed ? "," : ", ").
gsub(", \n", ",\n")
end |
- (Sass::Script::Value::List) to_sass_script
Returns a SassScript representation of this selector.
144 145 146 147 148 149 150 151 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/selector/comma_sequence.rb', line 144
def to_sass_script
Sass::Script::Value::List.new(members.map do |seq|
Sass::Script::Value::List.new(seq.members.map do |component|
next if component == "\n"
Sass::Script::Value::String.new(component.to_s)
end.compact, :space)
end, :comma)
end |
- (CommaSequence?) unify(other)
Unifies this with another comma selector to produce a selector that matches (a subset of) the intersection of the two inputs.
136 137 138 139 | # File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/selector/comma_sequence.rb', line 136
def unify(other)
results = members.map {|seq1| other.members.map {|seq2| seq1.unify(seq2)}}.flatten.compact
results.empty? ? nil : CommaSequence.new(results.map {|cseq| cseq.members}.flatten)
end |