Class: Sass::Selector::CommaSequence
- Inherits:
-
AbstractSequence
- Object
- AbstractSequence
- Sass::Selector::CommaSequence
- Defined in:
- lib/sass/selector/comma_sequence.rb
Overview
A comma-separated sequence of selectors.
Instance Attribute Summary collapse
-
#members ⇒ Array<Sequence>
readonly
The comma-separated selector sequences represented by this class.
Attributes inherited from AbstractSequence
Instance Method Summary collapse
-
#do_extend(extends, parent_directives) ⇒ CommaSequence
Non-destrucively extends this selector with the extensions specified in a hash (which should come from Tree::Visitors::Cssize).
-
#initialize(seqs) ⇒ CommaSequence
constructor
A new instance of CommaSequence.
-
#inspect ⇒ String
Returns a string representation of the sequence.
-
#resolve_parent_refs(super_cseq, implicit_parent = true) ⇒ CommaSequence
Resolves the Parent selectors within this selector by replacing them with the given parent selector, handling commas appropriately.
- #to_a
Methods inherited from AbstractSequence
#_specificity, #eql?, #has_placeholder?, #hash, #specificity, #to_s
Constructor Details
#initialize(seqs) ⇒ CommaSequence
Returns a new instance of CommaSequence.
12 13 14 |
# File 'lib/sass/selector/comma_sequence.rb', line 12
def initialize(seqs)
@members = seqs
end
|
Instance Attribute Details
#members ⇒ Array<Sequence> (readonly)
The comma-separated selector sequences represented by this class.
9 10 11 |
# File 'lib/sass/selector/comma_sequence.rb', line 9
def members
@members
end
|
Instance Method Details
#do_extend(extends, parent_directives) ⇒ CommaSequence
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
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/sass/selector/comma_sequence.rb', line 58
def do_extend(extends, parent_directives)
CommaSequence.new(members.map do |seq|
extended = seq.do_extend(extends, parent_directives)
# First Law of Extend: the result of extending a selector should
# always contain the base selector.
#
# See https://github.com/nex3/sass/issues/324.
extended.unshift seq unless seq.has_placeholder? || extended.include?(seq)
extended
end.flatten)
end
|
#inspect ⇒ String
Returns a string representation of the sequence. This is basically the selector string.
74 75 76 |
# File 'lib/sass/selector/comma_sequence.rb', line 74
def inspect
members.map {|m| m.inspect}.join(", ")
end
|
#resolve_parent_refs(super_cseq, implicit_parent = true) ⇒ CommaSequence
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 39 40 41 42 43 |
# File 'lib/sass/selector/comma_sequence.rb', line 26
def resolve_parent_refs(super_cseq, implicit_parent = true)
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(Sass::Util.flatten_vertically(@members.map do |seq|
seq.resolve_parent_refs(super_cseq, implicit_parent).members
end))
end
|
#to_a
79 80 81 82 |
# File 'lib/sass/selector/comma_sequence.rb', line 79
def to_a
arr = Sass::Util.intersperse(@members.map {|m| m.to_a}, ", ").flatten
Sass::Util.replace_subseq(arr, [", ", "\n"], [",\n"])
end
|