oreorenasass 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.yardopts +11 -0
- data/CONTRIBUTING +3 -0
- data/MIT-LICENSE +20 -0
- data/README.md +221 -0
- data/Rakefile +370 -0
- data/VERSION +1 -0
- data/VERSION_NAME +1 -0
- data/bin/sass +13 -0
- data/bin/sass-convert +12 -0
- data/bin/scss +13 -0
- data/extra/update_watch.rb +13 -0
- data/init.rb +18 -0
- data/lib/sass/cache_stores/base.rb +88 -0
- data/lib/sass/cache_stores/chain.rb +34 -0
- data/lib/sass/cache_stores/filesystem.rb +60 -0
- data/lib/sass/cache_stores/memory.rb +47 -0
- data/lib/sass/cache_stores/null.rb +25 -0
- data/lib/sass/cache_stores.rb +15 -0
- data/lib/sass/callbacks.rb +67 -0
- data/lib/sass/css.rb +407 -0
- data/lib/sass/engine.rb +1181 -0
- data/lib/sass/environment.rb +191 -0
- data/lib/sass/error.rb +198 -0
- data/lib/sass/exec/base.rb +187 -0
- data/lib/sass/exec/sass_convert.rb +264 -0
- data/lib/sass/exec/sass_scss.rb +424 -0
- data/lib/sass/exec.rb +9 -0
- data/lib/sass/features.rb +47 -0
- data/lib/sass/importers/base.rb +182 -0
- data/lib/sass/importers/filesystem.rb +211 -0
- data/lib/sass/importers.rb +22 -0
- data/lib/sass/logger/base.rb +30 -0
- data/lib/sass/logger/log_level.rb +45 -0
- data/lib/sass/logger.rb +12 -0
- data/lib/sass/media.rb +210 -0
- data/lib/sass/plugin/compiler.rb +565 -0
- data/lib/sass/plugin/configuration.rb +118 -0
- data/lib/sass/plugin/generic.rb +15 -0
- data/lib/sass/plugin/merb.rb +48 -0
- data/lib/sass/plugin/rack.rb +60 -0
- data/lib/sass/plugin/rails.rb +47 -0
- data/lib/sass/plugin/staleness_checker.rb +199 -0
- data/lib/sass/plugin.rb +133 -0
- data/lib/sass/railtie.rb +10 -0
- data/lib/sass/repl.rb +57 -0
- data/lib/sass/root.rb +7 -0
- data/lib/sass/script/css_lexer.rb +33 -0
- data/lib/sass/script/css_parser.rb +34 -0
- data/lib/sass/script/functions.rb +2626 -0
- data/lib/sass/script/lexer.rb +449 -0
- data/lib/sass/script/parser.rb +637 -0
- data/lib/sass/script/tree/funcall.rb +306 -0
- data/lib/sass/script/tree/interpolation.rb +118 -0
- data/lib/sass/script/tree/list_literal.rb +77 -0
- data/lib/sass/script/tree/literal.rb +45 -0
- data/lib/sass/script/tree/map_literal.rb +64 -0
- data/lib/sass/script/tree/node.rb +109 -0
- data/lib/sass/script/tree/operation.rb +103 -0
- data/lib/sass/script/tree/selector.rb +26 -0
- data/lib/sass/script/tree/string_interpolation.rb +104 -0
- data/lib/sass/script/tree/unary_operation.rb +69 -0
- data/lib/sass/script/tree/variable.rb +57 -0
- data/lib/sass/script/tree.rb +16 -0
- data/lib/sass/script/value/arg_list.rb +36 -0
- data/lib/sass/script/value/base.rb +240 -0
- data/lib/sass/script/value/bool.rb +35 -0
- data/lib/sass/script/value/color.rb +680 -0
- data/lib/sass/script/value/helpers.rb +262 -0
- data/lib/sass/script/value/list.rb +113 -0
- data/lib/sass/script/value/map.rb +70 -0
- data/lib/sass/script/value/null.rb +44 -0
- data/lib/sass/script/value/number.rb +530 -0
- data/lib/sass/script/value/string.rb +97 -0
- data/lib/sass/script/value.rb +11 -0
- data/lib/sass/script.rb +66 -0
- data/lib/sass/scss/css_parser.rb +42 -0
- data/lib/sass/scss/parser.rb +1209 -0
- data/lib/sass/scss/rx.rb +141 -0
- data/lib/sass/scss/script_lexer.rb +15 -0
- data/lib/sass/scss/script_parser.rb +25 -0
- data/lib/sass/scss/static_parser.rb +368 -0
- data/lib/sass/scss.rb +16 -0
- data/lib/sass/selector/abstract_sequence.rb +109 -0
- data/lib/sass/selector/comma_sequence.rb +175 -0
- data/lib/sass/selector/pseudo.rb +256 -0
- data/lib/sass/selector/sequence.rb +600 -0
- data/lib/sass/selector/simple.rb +117 -0
- data/lib/sass/selector/simple_sequence.rb +325 -0
- data/lib/sass/selector.rb +326 -0
- data/lib/sass/shared.rb +76 -0
- data/lib/sass/source/map.rb +210 -0
- data/lib/sass/source/position.rb +39 -0
- data/lib/sass/source/range.rb +41 -0
- data/lib/sass/stack.rb +120 -0
- data/lib/sass/supports.rb +227 -0
- data/lib/sass/tree/at_root_node.rb +83 -0
- data/lib/sass/tree/charset_node.rb +22 -0
- data/lib/sass/tree/comment_node.rb +82 -0
- data/lib/sass/tree/content_node.rb +9 -0
- data/lib/sass/tree/css_import_node.rb +60 -0
- data/lib/sass/tree/debug_node.rb +18 -0
- data/lib/sass/tree/directive_node.rb +59 -0
- data/lib/sass/tree/each_node.rb +24 -0
- data/lib/sass/tree/error_node.rb +18 -0
- data/lib/sass/tree/extend_node.rb +43 -0
- data/lib/sass/tree/for_node.rb +36 -0
- data/lib/sass/tree/function_node.rb +39 -0
- data/lib/sass/tree/if_node.rb +52 -0
- data/lib/sass/tree/import_node.rb +74 -0
- data/lib/sass/tree/keyframe_rule_node.rb +15 -0
- data/lib/sass/tree/media_node.rb +48 -0
- data/lib/sass/tree/mixin_def_node.rb +38 -0
- data/lib/sass/tree/mixin_node.rb +52 -0
- data/lib/sass/tree/node.rb +238 -0
- data/lib/sass/tree/prop_node.rb +171 -0
- data/lib/sass/tree/return_node.rb +19 -0
- data/lib/sass/tree/root_node.rb +44 -0
- data/lib/sass/tree/rule_node.rb +145 -0
- data/lib/sass/tree/supports_node.rb +38 -0
- data/lib/sass/tree/trace_node.rb +33 -0
- data/lib/sass/tree/variable_node.rb +36 -0
- data/lib/sass/tree/visitors/base.rb +72 -0
- data/lib/sass/tree/visitors/check_nesting.rb +177 -0
- data/lib/sass/tree/visitors/convert.rb +334 -0
- data/lib/sass/tree/visitors/cssize.rb +369 -0
- data/lib/sass/tree/visitors/deep_copy.rb +107 -0
- data/lib/sass/tree/visitors/extend.rb +68 -0
- data/lib/sass/tree/visitors/perform.rb +539 -0
- data/lib/sass/tree/visitors/set_options.rb +139 -0
- data/lib/sass/tree/visitors/to_css.rb +381 -0
- data/lib/sass/tree/warn_node.rb +18 -0
- data/lib/sass/tree/while_node.rb +18 -0
- data/lib/sass/util/cross_platform_random.rb +19 -0
- data/lib/sass/util/multibyte_string_scanner.rb +157 -0
- data/lib/sass/util/normalized_map.rb +130 -0
- data/lib/sass/util/ordered_hash.rb +192 -0
- data/lib/sass/util/subset_map.rb +110 -0
- data/lib/sass/util/test.rb +9 -0
- data/lib/sass/util.rb +1318 -0
- data/lib/sass/version.rb +124 -0
- data/lib/sass.rb +102 -0
- data/rails/init.rb +1 -0
- data/test/sass/cache_test.rb +131 -0
- data/test/sass/callbacks_test.rb +61 -0
- data/test/sass/compiler_test.rb +232 -0
- data/test/sass/conversion_test.rb +2054 -0
- data/test/sass/css2sass_test.rb +477 -0
- data/test/sass/data/hsl-rgb.txt +319 -0
- data/test/sass/encoding_test.rb +219 -0
- data/test/sass/engine_test.rb +3301 -0
- data/test/sass/exec_test.rb +86 -0
- data/test/sass/extend_test.rb +1661 -0
- data/test/sass/fixtures/test_staleness_check_across_importers.css +1 -0
- data/test/sass/fixtures/test_staleness_check_across_importers.scss +1 -0
- data/test/sass/functions_test.rb +1926 -0
- data/test/sass/importer_test.rb +412 -0
- data/test/sass/logger_test.rb +58 -0
- data/test/sass/mock_importer.rb +49 -0
- data/test/sass/more_results/more1.css +9 -0
- data/test/sass/more_results/more1_with_line_comments.css +26 -0
- data/test/sass/more_results/more_import.css +29 -0
- data/test/sass/more_templates/_more_partial.sass +2 -0
- data/test/sass/more_templates/more1.sass +23 -0
- data/test/sass/more_templates/more_import.sass +11 -0
- data/test/sass/plugin_test.rb +554 -0
- data/test/sass/results/alt.css +4 -0
- data/test/sass/results/basic.css +9 -0
- data/test/sass/results/cached_import_option.css +3 -0
- data/test/sass/results/compact.css +5 -0
- data/test/sass/results/complex.css +86 -0
- data/test/sass/results/compressed.css +1 -0
- data/test/sass/results/expanded.css +19 -0
- data/test/sass/results/filename_fn.css +3 -0
- data/test/sass/results/if.css +3 -0
- data/test/sass/results/import.css +31 -0
- data/test/sass/results/import_charset.css +5 -0
- data/test/sass/results/import_charset_1_8.css +5 -0
- data/test/sass/results/import_charset_ibm866.css +5 -0
- data/test/sass/results/import_content.css +1 -0
- data/test/sass/results/line_numbers.css +49 -0
- data/test/sass/results/mixins.css +95 -0
- data/test/sass/results/multiline.css +24 -0
- data/test/sass/results/nested.css +22 -0
- data/test/sass/results/options.css +1 -0
- data/test/sass/results/parent_ref.css +13 -0
- data/test/sass/results/script.css +16 -0
- data/test/sass/results/scss_import.css +31 -0
- data/test/sass/results/scss_importee.css +2 -0
- data/test/sass/results/subdir/nested_subdir/nested_subdir.css +1 -0
- data/test/sass/results/subdir/subdir.css +3 -0
- data/test/sass/results/units.css +11 -0
- data/test/sass/results/warn.css +0 -0
- data/test/sass/results/warn_imported.css +0 -0
- data/test/sass/script_conversion_test.rb +328 -0
- data/test/sass/script_test.rb +1054 -0
- data/test/sass/scss/css_test.rb +1215 -0
- data/test/sass/scss/rx_test.rb +156 -0
- data/test/sass/scss/scss_test.rb +3900 -0
- data/test/sass/scss/test_helper.rb +37 -0
- data/test/sass/source_map_test.rb +977 -0
- data/test/sass/superselector_test.rb +191 -0
- data/test/sass/templates/_cached_import_option_partial.scss +1 -0
- data/test/sass/templates/_double_import_loop2.sass +1 -0
- data/test/sass/templates/_filename_fn_import.scss +11 -0
- data/test/sass/templates/_imported_charset_ibm866.sass +4 -0
- data/test/sass/templates/_imported_charset_utf8.sass +4 -0
- data/test/sass/templates/_imported_content.sass +3 -0
- data/test/sass/templates/_partial.sass +2 -0
- data/test/sass/templates/_same_name_different_partiality.scss +1 -0
- data/test/sass/templates/alt.sass +16 -0
- data/test/sass/templates/basic.sass +23 -0
- data/test/sass/templates/bork1.sass +2 -0
- data/test/sass/templates/bork2.sass +2 -0
- data/test/sass/templates/bork3.sass +2 -0
- data/test/sass/templates/bork4.sass +2 -0
- data/test/sass/templates/bork5.sass +3 -0
- data/test/sass/templates/cached_import_option.scss +3 -0
- data/test/sass/templates/compact.sass +17 -0
- data/test/sass/templates/complex.sass +305 -0
- data/test/sass/templates/compressed.sass +15 -0
- data/test/sass/templates/double_import_loop1.sass +1 -0
- data/test/sass/templates/expanded.sass +17 -0
- data/test/sass/templates/filename_fn.scss +18 -0
- data/test/sass/templates/if.sass +11 -0
- data/test/sass/templates/import.sass +12 -0
- data/test/sass/templates/import_charset.sass +9 -0
- data/test/sass/templates/import_charset_1_8.sass +6 -0
- data/test/sass/templates/import_charset_ibm866.sass +11 -0
- data/test/sass/templates/import_content.sass +4 -0
- data/test/sass/templates/importee.less +2 -0
- data/test/sass/templates/importee.sass +19 -0
- data/test/sass/templates/line_numbers.sass +13 -0
- data/test/sass/templates/mixin_bork.sass +5 -0
- data/test/sass/templates/mixins.sass +76 -0
- data/test/sass/templates/multiline.sass +20 -0
- data/test/sass/templates/nested.sass +25 -0
- data/test/sass/templates/nested_bork1.sass +2 -0
- data/test/sass/templates/nested_bork2.sass +2 -0
- data/test/sass/templates/nested_bork3.sass +2 -0
- data/test/sass/templates/nested_bork4.sass +2 -0
- data/test/sass/templates/nested_import.sass +2 -0
- data/test/sass/templates/nested_mixin_bork.sass +6 -0
- data/test/sass/templates/options.sass +2 -0
- data/test/sass/templates/parent_ref.sass +25 -0
- data/test/sass/templates/same_name_different_ext.sass +2 -0
- data/test/sass/templates/same_name_different_ext.scss +1 -0
- data/test/sass/templates/same_name_different_partiality.scss +1 -0
- data/test/sass/templates/script.sass +101 -0
- data/test/sass/templates/scss_import.scss +12 -0
- data/test/sass/templates/scss_importee.scss +1 -0
- data/test/sass/templates/single_import_loop.sass +1 -0
- data/test/sass/templates/subdir/import_up1.scss +1 -0
- data/test/sass/templates/subdir/import_up2.scss +1 -0
- data/test/sass/templates/subdir/nested_subdir/_nested_partial.sass +2 -0
- data/test/sass/templates/subdir/nested_subdir/nested_subdir.sass +3 -0
- data/test/sass/templates/subdir/subdir.sass +6 -0
- data/test/sass/templates/units.sass +11 -0
- data/test/sass/templates/warn.sass +3 -0
- data/test/sass/templates/warn_imported.sass +4 -0
- data/test/sass/test_helper.rb +8 -0
- data/test/sass/util/multibyte_string_scanner_test.rb +147 -0
- data/test/sass/util/normalized_map_test.rb +51 -0
- data/test/sass/util/subset_map_test.rb +91 -0
- data/test/sass/util_test.rb +467 -0
- data/test/sass/value_helpers_test.rb +179 -0
- data/test/test_helper.rb +109 -0
- metadata +386 -0
@@ -0,0 +1,117 @@
|
|
1
|
+
module Sass
|
2
|
+
module Selector
|
3
|
+
# The abstract superclass for simple selectors
|
4
|
+
# (that is, those that don't compose multiple selectors).
|
5
|
+
class Simple
|
6
|
+
# The line of the Sass template on which this selector was declared.
|
7
|
+
#
|
8
|
+
# @return [Fixnum]
|
9
|
+
attr_accessor :line
|
10
|
+
|
11
|
+
# The name of the file in which this selector was declared,
|
12
|
+
# or `nil` if it was not declared in a file (e.g. on stdin).
|
13
|
+
#
|
14
|
+
# @return [String, nil]
|
15
|
+
attr_accessor :filename
|
16
|
+
|
17
|
+
# @see #to_s
|
18
|
+
#
|
19
|
+
# @return [String]
|
20
|
+
def inspect
|
21
|
+
to_s
|
22
|
+
end
|
23
|
+
|
24
|
+
# Returns the selector string.
|
25
|
+
#
|
26
|
+
# @return [String]
|
27
|
+
def to_s
|
28
|
+
Sass::Util.abstract(self)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Returns a hash code for this selector object.
|
32
|
+
#
|
33
|
+
# By default, this is based on the value of \{#to\_a},
|
34
|
+
# so if that contains information irrelevant to the identity of the selector,
|
35
|
+
# this should be overridden.
|
36
|
+
#
|
37
|
+
# @return [Fixnum]
|
38
|
+
def hash
|
39
|
+
@_hash ||= equality_key.hash
|
40
|
+
end
|
41
|
+
|
42
|
+
# Checks equality between this and another object.
|
43
|
+
#
|
44
|
+
# By default, this is based on the value of \{#to\_a},
|
45
|
+
# so if that contains information irrelevant to the identity of the selector,
|
46
|
+
# this should be overridden.
|
47
|
+
#
|
48
|
+
# @param other [Object] The object to test equality against
|
49
|
+
# @return [Boolean] Whether or not this is equal to `other`
|
50
|
+
def eql?(other)
|
51
|
+
other.class == self.class && other.hash == hash && other.equality_key == equality_key
|
52
|
+
end
|
53
|
+
alias_method :==, :eql?
|
54
|
+
|
55
|
+
# Unifies this selector with a {SimpleSequence}'s {SimpleSequence#members members array},
|
56
|
+
# returning another `SimpleSequence` members array
|
57
|
+
# that matches both this selector and the input selector.
|
58
|
+
#
|
59
|
+
# By default, this just appends this selector to the end of the array
|
60
|
+
# (or returns the original array if this selector already exists in it).
|
61
|
+
#
|
62
|
+
# @param sels [Array<Simple>] A {SimpleSequence}'s {SimpleSequence#members members array}
|
63
|
+
# @return [Array<Simple>, nil] A {SimpleSequence} {SimpleSequence#members members array}
|
64
|
+
# matching both `sels` and this selector,
|
65
|
+
# or `nil` if this is impossible (e.g. unifying `#foo` and `#bar`)
|
66
|
+
# @raise [Sass::SyntaxError] If this selector cannot be unified.
|
67
|
+
# This will only ever occur when a dynamic selector,
|
68
|
+
# such as {Parent} or {Interpolation}, is used in unification.
|
69
|
+
# Since these selectors should be resolved
|
70
|
+
# by the time extension and unification happen,
|
71
|
+
# this exception will only ever be raised as a result of programmer error
|
72
|
+
def unify(sels)
|
73
|
+
return sels if sels.any? {|sel2| eql?(sel2)}
|
74
|
+
sels_with_ix = Sass::Util.enum_with_index(sels)
|
75
|
+
_, i =
|
76
|
+
if is_a?(Pseudo)
|
77
|
+
sels_with_ix.find {|sel, _| sel.is_a?(Pseudo) && (sels.last.type == :element)}
|
78
|
+
else
|
79
|
+
sels_with_ix.find {|sel, _| sel.is_a?(Pseudo)}
|
80
|
+
end
|
81
|
+
return sels + [self] unless i
|
82
|
+
sels[0...i] + [self] + sels[i..-1]
|
83
|
+
end
|
84
|
+
|
85
|
+
protected
|
86
|
+
|
87
|
+
# Returns the key used for testing whether selectors are equal.
|
88
|
+
#
|
89
|
+
# This is a cached version of \{#to\_s}.
|
90
|
+
#
|
91
|
+
# @return [String]
|
92
|
+
def equality_key
|
93
|
+
@equality_key ||= to_s
|
94
|
+
end
|
95
|
+
|
96
|
+
# Unifies two namespaces,
|
97
|
+
# returning a namespace that works for both of them if possible.
|
98
|
+
#
|
99
|
+
# @param ns1 [String, nil] The first namespace.
|
100
|
+
# `nil` means none specified, e.g. `foo`.
|
101
|
+
# The empty string means no namespace specified, e.g. `|foo`.
|
102
|
+
# `"*"` means any namespace is allowed, e.g. `*|foo`.
|
103
|
+
# @param ns2 [String, nil] The second namespace. See `ns1`.
|
104
|
+
# @return [Array(String or nil, Boolean)]
|
105
|
+
# The first value is the unified namespace, or `nil` for no namespace.
|
106
|
+
# The second value is whether or not a namespace that works for both inputs
|
107
|
+
# could be found at all.
|
108
|
+
# If the second value is `false`, the first should be ignored.
|
109
|
+
def unify_namespaces(ns1, ns2)
|
110
|
+
return nil, false unless ns1 == ns2 || ns1.nil? || ns1 == '*' || ns2.nil? || ns2 == '*'
|
111
|
+
return ns2, true if ns1 == '*'
|
112
|
+
return ns1, true if ns2 == '*'
|
113
|
+
[ns1 || ns2, true]
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,325 @@
|
|
1
|
+
module Sass
|
2
|
+
module Selector
|
3
|
+
# A unseparated sequence of selectors
|
4
|
+
# that all apply to a single element.
|
5
|
+
# For example, `.foo#bar[attr=baz]` is a simple sequence
|
6
|
+
# of the selectors `.foo`, `#bar`, and `[attr=baz]`.
|
7
|
+
class SimpleSequence < AbstractSequence
|
8
|
+
# The array of individual selectors.
|
9
|
+
#
|
10
|
+
# @return [Array<Simple>]
|
11
|
+
attr_accessor :members
|
12
|
+
|
13
|
+
# The extending selectors that caused this selector sequence to be
|
14
|
+
# generated. For example:
|
15
|
+
#
|
16
|
+
# a.foo { ... }
|
17
|
+
# b.bar {@extend a}
|
18
|
+
# c.baz {@extend b}
|
19
|
+
#
|
20
|
+
# The generated selector `b.foo.bar` has `{b.bar}` as its `sources` set,
|
21
|
+
# and the generated selector `c.foo.bar.baz` has `{b.bar, c.baz}` as its
|
22
|
+
# `sources` set.
|
23
|
+
#
|
24
|
+
# This is populated during the {Sequence#do_extend} process.
|
25
|
+
#
|
26
|
+
# @return {Set<Sequence>}
|
27
|
+
attr_accessor :sources
|
28
|
+
|
29
|
+
# This sequence source range.
|
30
|
+
#
|
31
|
+
# @return [Sass::Source::Range]
|
32
|
+
attr_accessor :source_range
|
33
|
+
|
34
|
+
# @see \{#subject?}
|
35
|
+
attr_writer :subject
|
36
|
+
|
37
|
+
# Returns the element or universal selector in this sequence,
|
38
|
+
# if it exists.
|
39
|
+
#
|
40
|
+
# @return [Element, Universal, nil]
|
41
|
+
def base
|
42
|
+
@base ||= (members.first if members.first.is_a?(Element) || members.first.is_a?(Universal))
|
43
|
+
end
|
44
|
+
|
45
|
+
def pseudo_elements
|
46
|
+
@pseudo_elements ||= members.select {|sel| sel.is_a?(Pseudo) && sel.type == :element}
|
47
|
+
end
|
48
|
+
|
49
|
+
def selector_pseudo_classes
|
50
|
+
@selector_pseudo_classes ||= members.
|
51
|
+
select {|sel| sel.is_a?(Pseudo) && sel.type == :class && sel.selector}.
|
52
|
+
group_by {|sel| sel.normalized_name}
|
53
|
+
end
|
54
|
+
|
55
|
+
# Returns the non-base, non-pseudo-element selectors in this sequence.
|
56
|
+
#
|
57
|
+
# @return [Set<Simple>]
|
58
|
+
def rest
|
59
|
+
@rest ||= Set.new(members - [base] - pseudo_elements)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Whether or not this compound selector is the subject of the parent
|
63
|
+
# selector; that is, whether it is prepended with `$` and represents the
|
64
|
+
# actual element that will be selected.
|
65
|
+
#
|
66
|
+
# @return [Boolean]
|
67
|
+
def subject?
|
68
|
+
@subject
|
69
|
+
end
|
70
|
+
|
71
|
+
# @param selectors [Array<Simple>] See \{#members}
|
72
|
+
# @param subject [Boolean] See \{#subject?}
|
73
|
+
# @param source_range [Sass::Source::Range]
|
74
|
+
def initialize(selectors, subject, source_range = nil)
|
75
|
+
@members = selectors
|
76
|
+
@subject = subject
|
77
|
+
@sources = Set.new
|
78
|
+
@source_range = source_range
|
79
|
+
end
|
80
|
+
|
81
|
+
# Resolves the {Parent} selectors within this selector
|
82
|
+
# by replacing them with the given parent selector,
|
83
|
+
# handling commas appropriately.
|
84
|
+
#
|
85
|
+
# @param super_cseq [CommaSequence] The parent selector
|
86
|
+
# @return [CommaSequence] This selector, with parent references resolved
|
87
|
+
# @raise [Sass::SyntaxError] If a parent selector is invalid
|
88
|
+
def resolve_parent_refs(super_cseq)
|
89
|
+
# Parent selector only appears as the first selector in the sequence
|
90
|
+
unless (parent = @members.first).is_a?(Parent)
|
91
|
+
return CommaSequence.new([Sequence.new([self])])
|
92
|
+
end
|
93
|
+
|
94
|
+
return super_cseq if @members.size == 1 && parent.suffix.nil?
|
95
|
+
|
96
|
+
CommaSequence.new(super_cseq.members.map do |super_seq|
|
97
|
+
members = super_seq.members.dup
|
98
|
+
newline = members.pop if members.last == "\n"
|
99
|
+
unless members.last.is_a?(SimpleSequence)
|
100
|
+
raise Sass::SyntaxError.new("Invalid parent selector for \"#{self}\": \"" +
|
101
|
+
super_seq.to_s + '"')
|
102
|
+
end
|
103
|
+
|
104
|
+
parent_sub = members.last.members
|
105
|
+
unless parent.suffix.nil?
|
106
|
+
parent_sub = parent_sub.dup
|
107
|
+
parent_sub[-1] = parent_sub.last.dup
|
108
|
+
case parent_sub.last
|
109
|
+
when Sass::Selector::Class, Sass::Selector::Id, Sass::Selector::Placeholder
|
110
|
+
parent_sub[-1] = parent_sub.last.class.new(parent_sub.last.name + parent.suffix)
|
111
|
+
when Sass::Selector::Element
|
112
|
+
parent_sub[-1] = parent_sub.last.class.new(
|
113
|
+
parent_sub.last.name + parent.suffix,
|
114
|
+
parent_sub.last.namespace)
|
115
|
+
when Sass::Selector::Pseudo
|
116
|
+
if parent_sub.last.arg || parent_sub.last.selector
|
117
|
+
raise Sass::SyntaxError.new("Invalid parent selector for \"#{self}\": \"" +
|
118
|
+
super_seq.to_s + '"')
|
119
|
+
end
|
120
|
+
parent_sub[-1] = Sass::Selector::Pseudo.new(
|
121
|
+
parent_sub.last.type,
|
122
|
+
parent_sub.last.name + parent.suffix,
|
123
|
+
nil, nil)
|
124
|
+
else
|
125
|
+
raise Sass::SyntaxError.new("Invalid parent selector for \"#{self}\": \"" +
|
126
|
+
super_seq.to_s + '"')
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
Sequence.new(members[0...-1] +
|
131
|
+
[SimpleSequence.new(parent_sub + @members[1..-1], subject?)] +
|
132
|
+
[newline].compact)
|
133
|
+
end)
|
134
|
+
end
|
135
|
+
|
136
|
+
# Non-destructively extends this selector with the extensions specified in a hash
|
137
|
+
# (which should come from {Sass::Tree::Visitors::Cssize}).
|
138
|
+
#
|
139
|
+
# @param extends [{Selector::Simple =>
|
140
|
+
# Sass::Tree::Visitors::Cssize::Extend}]
|
141
|
+
# The extensions to perform on this selector
|
142
|
+
# @param parent_directives [Array<Sass::Tree::DirectiveNode>]
|
143
|
+
# The directives containing this selector.
|
144
|
+
# @param seen [Set<Array<Selector::Simple>>]
|
145
|
+
# The set of simple sequences that are currently being replaced.
|
146
|
+
# @param original [Boolean]
|
147
|
+
# Whether this is the original selector being extended, as opposed to
|
148
|
+
# the result of a previous extension that's being re-extended.
|
149
|
+
# @return [Array<Sequence>] A list of selectors generated
|
150
|
+
# by extending this selector with `extends`.
|
151
|
+
# @see CommaSequence#do_extend
|
152
|
+
def do_extend(extends, parent_directives, replace, seen)
|
153
|
+
seen_with_pseudo_selectors = seen.dup
|
154
|
+
|
155
|
+
modified_original = false
|
156
|
+
members = Sass::Util.enum_with_index(self.members).map do |sel, i|
|
157
|
+
next sel unless sel.is_a?(Pseudo) && sel.selector
|
158
|
+
next sel if seen.include?([sel])
|
159
|
+
extended = sel.selector.do_extend(extends, parent_directives, replace, seen, !:original)
|
160
|
+
next sel if extended == sel.selector
|
161
|
+
extended.members.reject! {|seq| seq.has_placeholder?}
|
162
|
+
modified_original = true
|
163
|
+
result = sel.with_selector(extended)
|
164
|
+
seen_with_pseudo_selectors << [result]
|
165
|
+
result
|
166
|
+
end
|
167
|
+
|
168
|
+
groups = Sass::Util.group_by_to_a(extends[members.to_set]) {|ex| ex.extender}
|
169
|
+
groups.map! do |seq, group|
|
170
|
+
sels = group.map {|e| e.target}.flatten
|
171
|
+
# If A {@extend B} and C {...},
|
172
|
+
# seq is A, sels is B, and self is C
|
173
|
+
|
174
|
+
self_without_sel = Sass::Util.array_minus(members, sels)
|
175
|
+
group.each {|e| e.result = :failed_to_unify unless e.result == :succeeded}
|
176
|
+
unified = seq.members.last.unify(SimpleSequence.new(self_without_sel, subject?))
|
177
|
+
next unless unified
|
178
|
+
group.each {|e| e.result = :succeeded}
|
179
|
+
group.each {|e| check_directives_match!(e, parent_directives)}
|
180
|
+
new_seq = Sequence.new(seq.members[0...-1] + [unified])
|
181
|
+
new_seq.add_sources!(sources + [seq])
|
182
|
+
[sels, new_seq]
|
183
|
+
end
|
184
|
+
groups.compact!
|
185
|
+
groups.map! do |sels, seq|
|
186
|
+
next [] if seen.include?(sels)
|
187
|
+
seq.do_extend(
|
188
|
+
extends, parent_directives, !:replace, seen_with_pseudo_selectors + [sels], !:original)
|
189
|
+
end
|
190
|
+
groups.flatten!
|
191
|
+
|
192
|
+
if modified_original || !replace || groups.empty?
|
193
|
+
# First Law of Extend: the result of extending a selector should
|
194
|
+
# (almost) always contain the base selector.
|
195
|
+
#
|
196
|
+
# See https://github.com/nex3/sass/issues/324.
|
197
|
+
original = Sequence.new([SimpleSequence.new(members, @subject, source_range)])
|
198
|
+
original.add_sources! sources
|
199
|
+
groups.unshift original
|
200
|
+
end
|
201
|
+
groups.uniq!
|
202
|
+
groups
|
203
|
+
end
|
204
|
+
|
205
|
+
# Unifies this selector with another {SimpleSequence}, returning
|
206
|
+
# another `SimpleSequence` that is a subselector of both input
|
207
|
+
# selectors.
|
208
|
+
#
|
209
|
+
# @param other [SimpleSequence]
|
210
|
+
# @return [SimpleSequence, nil] A {SimpleSequence} matching both `sels` and this selector,
|
211
|
+
# or `nil` if this is impossible (e.g. unifying `#foo` and `#bar`)
|
212
|
+
# @raise [Sass::SyntaxError] If this selector cannot be unified.
|
213
|
+
# This will only ever occur when a dynamic selector,
|
214
|
+
# such as {Parent} or {Interpolation}, is used in unification.
|
215
|
+
# Since these selectors should be resolved
|
216
|
+
# by the time extension and unification happen,
|
217
|
+
# this exception will only ever be raised as a result of programmer error
|
218
|
+
def unify(other)
|
219
|
+
sseq = members.inject(other.members) do |member, sel|
|
220
|
+
return unless member
|
221
|
+
sel.unify(member)
|
222
|
+
end
|
223
|
+
return unless sseq
|
224
|
+
SimpleSequence.new(sseq, other.subject? || subject?)
|
225
|
+
end
|
226
|
+
|
227
|
+
# Returns whether or not this selector matches all elements
|
228
|
+
# that the given selector matches (as well as possibly more).
|
229
|
+
#
|
230
|
+
# @example
|
231
|
+
# (.foo).superselector?(.foo.bar) #=> true
|
232
|
+
# (.foo).superselector?(.bar) #=> false
|
233
|
+
# @param their_sseq [SimpleSequence]
|
234
|
+
# @param parents [Array<SimpleSequence, String>] The parent selectors of `their_sseq`, if any.
|
235
|
+
# @return [Boolean]
|
236
|
+
def superselector?(their_sseq, parents = [])
|
237
|
+
return false unless base.nil? || base.eql?(their_sseq.base)
|
238
|
+
return false unless pseudo_elements.eql?(their_sseq.pseudo_elements)
|
239
|
+
our_spcs = selector_pseudo_classes
|
240
|
+
their_spcs = their_sseq.selector_pseudo_classes
|
241
|
+
|
242
|
+
# Some psuedo-selectors can be subselectors of non-pseudo selectors.
|
243
|
+
# Pull those out here so we can efficiently check against them below.
|
244
|
+
their_subselector_pseudos = %w[matches any nth-child nth-last-child].
|
245
|
+
map {|name| their_spcs[name] || []}.flatten
|
246
|
+
|
247
|
+
# If `self`'s non-pseudo simple selectors aren't a subset of `their_sseq`'s,
|
248
|
+
# it's definitely not a superselector. This also considers being matched
|
249
|
+
# by `:matches` or `:any`.
|
250
|
+
return false unless rest.all? do |our_sel|
|
251
|
+
next true if our_sel.is_a?(Pseudo) && our_sel.selector
|
252
|
+
next true if their_sseq.rest.include?(our_sel)
|
253
|
+
their_subselector_pseudos.any? do |their_pseudo|
|
254
|
+
their_pseudo.selector.members.all? do |their_seq|
|
255
|
+
next false unless their_seq.members.length == 1
|
256
|
+
their_sseq = their_seq.members.first
|
257
|
+
next false unless their_sseq.is_a?(SimpleSequence)
|
258
|
+
their_sseq.rest.include?(our_sel)
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
our_spcs.all? do |name, pseudos|
|
264
|
+
pseudos.all? {|pseudo| pseudo.superselector?(their_sseq, parents)}
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
# @see Simple#to_s
|
269
|
+
def to_s
|
270
|
+
res = @members.join
|
271
|
+
res << '!' if subject?
|
272
|
+
res
|
273
|
+
end
|
274
|
+
|
275
|
+
# Returns a string representation of the sequence.
|
276
|
+
# This is basically the selector string.
|
277
|
+
#
|
278
|
+
# @return [String]
|
279
|
+
def inspect
|
280
|
+
res = members.map {|m| m.inspect}.join
|
281
|
+
res << '!' if subject?
|
282
|
+
res
|
283
|
+
end
|
284
|
+
|
285
|
+
# Return a copy of this simple sequence with `sources` merged into the
|
286
|
+
# {SimpleSequence#sources} set.
|
287
|
+
#
|
288
|
+
# @param sources [Set<Sequence>]
|
289
|
+
# @return [SimpleSequence]
|
290
|
+
def with_more_sources(sources)
|
291
|
+
sseq = dup
|
292
|
+
sseq.members = members.dup
|
293
|
+
sseq.sources = self.sources | sources
|
294
|
+
sseq
|
295
|
+
end
|
296
|
+
|
297
|
+
private
|
298
|
+
|
299
|
+
def check_directives_match!(extend, parent_directives)
|
300
|
+
dirs1 = extend.directives.map {|d| d.resolved_value}
|
301
|
+
dirs2 = parent_directives.map {|d| d.resolved_value}
|
302
|
+
return if Sass::Util.subsequence?(dirs1, dirs2)
|
303
|
+
line = extend.node.line
|
304
|
+
filename = extend.node.filename
|
305
|
+
|
306
|
+
# TODO(nweiz): this should use the Sass stack trace of the extend node,
|
307
|
+
# not the selector.
|
308
|
+
raise Sass::SyntaxError.new(<<MESSAGE)
|
309
|
+
You may not @extend an outer selector from within #{extend.directives.last.name}.
|
310
|
+
You may only @extend selectors within the same directive.
|
311
|
+
From "@extend #{extend.target.join(', ')}" on line #{line}#{" of #{filename}" if filename}.
|
312
|
+
MESSAGE
|
313
|
+
end
|
314
|
+
|
315
|
+
def _hash
|
316
|
+
[base, Sass::Util.set_hash(rest)].hash
|
317
|
+
end
|
318
|
+
|
319
|
+
def _eql?(other)
|
320
|
+
other.base.eql?(base) && other.pseudo_elements == pseudo_elements &&
|
321
|
+
Sass::Util.set_eql?(other.rest, rest) && other.subject? == subject?
|
322
|
+
end
|
323
|
+
end
|
324
|
+
end
|
325
|
+
end
|
@@ -0,0 +1,326 @@
|
|
1
|
+
require 'sass/selector/simple'
|
2
|
+
require 'sass/selector/abstract_sequence'
|
3
|
+
require 'sass/selector/comma_sequence'
|
4
|
+
require 'sass/selector/pseudo'
|
5
|
+
require 'sass/selector/sequence'
|
6
|
+
require 'sass/selector/simple_sequence'
|
7
|
+
|
8
|
+
module Sass
|
9
|
+
# A namespace for nodes in the parse tree for selectors.
|
10
|
+
#
|
11
|
+
# {CommaSequence} is the toplevel selector,
|
12
|
+
# representing a comma-separated sequence of {Sequence}s,
|
13
|
+
# such as `foo bar, baz bang`.
|
14
|
+
# {Sequence} is the next level,
|
15
|
+
# representing {SimpleSequence}s separated by combinators (e.g. descendant or child),
|
16
|
+
# such as `foo bar` or `foo > bar baz`.
|
17
|
+
# {SimpleSequence} is a sequence of selectors that all apply to a single element,
|
18
|
+
# such as `foo.bar[attr=val]`.
|
19
|
+
# Finally, {Simple} is the superclass of the simplest selectors,
|
20
|
+
# such as `.foo` or `#bar`.
|
21
|
+
module Selector
|
22
|
+
# The base used for calculating selector specificity. The spec says this
|
23
|
+
# should be "sufficiently high"; it's extremely unlikely that any single
|
24
|
+
# selector sequence will contain 1,000 simple selectors.
|
25
|
+
SPECIFICITY_BASE = 1_000
|
26
|
+
|
27
|
+
# A parent-referencing selector (`&` in Sass).
|
28
|
+
# The function of this is to be replaced by the parent selector
|
29
|
+
# in the nested hierarchy.
|
30
|
+
class Parent < Simple
|
31
|
+
# The identifier following the `&`. `nil` indicates no suffix.
|
32
|
+
#
|
33
|
+
# @return [String, nil]
|
34
|
+
attr_reader :suffix
|
35
|
+
|
36
|
+
# @param name [String, nil] See \{#suffix}
|
37
|
+
def initialize(suffix = nil)
|
38
|
+
@suffix = suffix
|
39
|
+
end
|
40
|
+
|
41
|
+
# @see Selector#to_s
|
42
|
+
def to_s
|
43
|
+
"&" + (@suffix || '')
|
44
|
+
end
|
45
|
+
|
46
|
+
# Always raises an exception.
|
47
|
+
#
|
48
|
+
# @raise [Sass::SyntaxError] Parent selectors should be resolved before unification
|
49
|
+
# @see Selector#unify
|
50
|
+
def unify(sels)
|
51
|
+
raise Sass::SyntaxError.new("[BUG] Cannot unify parent selectors.")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# A class selector (e.g. `.foo`).
|
56
|
+
class Class < Simple
|
57
|
+
# The class name.
|
58
|
+
#
|
59
|
+
# @return [String]
|
60
|
+
attr_reader :name
|
61
|
+
|
62
|
+
# @param name [String] The class name
|
63
|
+
def initialize(name)
|
64
|
+
@name = name
|
65
|
+
end
|
66
|
+
|
67
|
+
# @see Selector#to_s
|
68
|
+
def to_s
|
69
|
+
"." + @name
|
70
|
+
end
|
71
|
+
|
72
|
+
# @see AbstractSequence#specificity
|
73
|
+
def specificity
|
74
|
+
SPECIFICITY_BASE
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# An id selector (e.g. `#foo`).
|
79
|
+
class Id < Simple
|
80
|
+
# The id name.
|
81
|
+
#
|
82
|
+
# @return [String]
|
83
|
+
attr_reader :name
|
84
|
+
|
85
|
+
# @param name [String] The id name
|
86
|
+
def initialize(name)
|
87
|
+
@name = name
|
88
|
+
end
|
89
|
+
|
90
|
+
# @see Selector#to_s
|
91
|
+
def to_s
|
92
|
+
"#" + @name
|
93
|
+
end
|
94
|
+
|
95
|
+
# Returns `nil` if `sels` contains an {Id} selector
|
96
|
+
# with a different name than this one.
|
97
|
+
#
|
98
|
+
# @see Selector#unify
|
99
|
+
def unify(sels)
|
100
|
+
return if sels.any? {|sel2| sel2.is_a?(Id) && name != sel2.name}
|
101
|
+
super
|
102
|
+
end
|
103
|
+
|
104
|
+
# @see AbstractSequence#specificity
|
105
|
+
def specificity
|
106
|
+
SPECIFICITY_BASE**2
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
# A placeholder selector (e.g. `%foo`).
|
111
|
+
# This exists to be replaced via `@extend`.
|
112
|
+
# Rulesets using this selector will not be printed, but can be extended.
|
113
|
+
# Otherwise, this acts just like a class selector.
|
114
|
+
class Placeholder < Simple
|
115
|
+
# The placeholder name.
|
116
|
+
#
|
117
|
+
# @return [String]
|
118
|
+
attr_reader :name
|
119
|
+
|
120
|
+
# @param name [String] The placeholder name
|
121
|
+
def initialize(name)
|
122
|
+
@name = name
|
123
|
+
end
|
124
|
+
|
125
|
+
# @see Selector#to_s
|
126
|
+
def to_s
|
127
|
+
"%" + @name
|
128
|
+
end
|
129
|
+
|
130
|
+
# @see AbstractSequence#specificity
|
131
|
+
def specificity
|
132
|
+
SPECIFICITY_BASE
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
# A universal selector (`*` in CSS).
|
137
|
+
class Universal < Simple
|
138
|
+
# The selector namespace. `nil` means the default namespace, `""` means no
|
139
|
+
# namespace, `"*"` means any namespace.
|
140
|
+
#
|
141
|
+
# @return [String, nil]
|
142
|
+
attr_reader :namespace
|
143
|
+
|
144
|
+
# @param namespace [String, nil] See \{#namespace}
|
145
|
+
def initialize(namespace)
|
146
|
+
@namespace = namespace
|
147
|
+
end
|
148
|
+
|
149
|
+
# @see Selector#to_s
|
150
|
+
def to_s
|
151
|
+
@namespace ? "#{@namespace}|*" : "*"
|
152
|
+
end
|
153
|
+
|
154
|
+
# Unification of a universal selector is somewhat complicated,
|
155
|
+
# especially when a namespace is specified.
|
156
|
+
# If there is no namespace specified
|
157
|
+
# or any namespace is specified (namespace `"*"`),
|
158
|
+
# then `sel` is returned without change
|
159
|
+
# (unless it's empty, in which case `"*"` is required).
|
160
|
+
#
|
161
|
+
# If a namespace is specified
|
162
|
+
# but `sel` does not specify a namespace,
|
163
|
+
# then the given namespace is applied to `sel`,
|
164
|
+
# either by adding this {Universal} selector
|
165
|
+
# or applying this namespace to an existing {Element} selector.
|
166
|
+
#
|
167
|
+
# If both this selector *and* `sel` specify namespaces,
|
168
|
+
# those namespaces are unified via {Simple#unify_namespaces}
|
169
|
+
# and the unified namespace is used, if possible.
|
170
|
+
#
|
171
|
+
# @todo There are lots of cases that this documentation specifies;
|
172
|
+
# make sure we thoroughly test **all of them**.
|
173
|
+
# @todo Keep track of whether a default namespace has been declared
|
174
|
+
# and handle namespace-unspecified selectors accordingly.
|
175
|
+
# @todo If any branch of a CommaSequence ends up being just `"*"`,
|
176
|
+
# then all other branches should be eliminated
|
177
|
+
#
|
178
|
+
# @see Selector#unify
|
179
|
+
def unify(sels)
|
180
|
+
name =
|
181
|
+
case sels.first
|
182
|
+
when Universal; :universal
|
183
|
+
when Element; sels.first.name
|
184
|
+
else
|
185
|
+
return [self] + sels unless namespace.nil? || namespace == '*'
|
186
|
+
return sels unless sels.empty?
|
187
|
+
return [self]
|
188
|
+
end
|
189
|
+
|
190
|
+
ns, accept = unify_namespaces(namespace, sels.first.namespace)
|
191
|
+
return unless accept
|
192
|
+
[name == :universal ? Universal.new(ns) : Element.new(name, ns)] + sels[1..-1]
|
193
|
+
end
|
194
|
+
|
195
|
+
# @see AbstractSequence#specificity
|
196
|
+
def specificity
|
197
|
+
0
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
# An element selector (e.g. `h1`).
|
202
|
+
class Element < Simple
|
203
|
+
# The element name.
|
204
|
+
#
|
205
|
+
# @return [String]
|
206
|
+
attr_reader :name
|
207
|
+
|
208
|
+
# The selector namespace. `nil` means the default namespace, `""` means no
|
209
|
+
# namespace, `"*"` means any namespace.
|
210
|
+
#
|
211
|
+
# @return [String, nil]
|
212
|
+
attr_reader :namespace
|
213
|
+
|
214
|
+
# @param name [String] The element name
|
215
|
+
# @param namespace [String, nil] See \{#namespace}
|
216
|
+
def initialize(name, namespace)
|
217
|
+
@name = name
|
218
|
+
@namespace = namespace
|
219
|
+
end
|
220
|
+
|
221
|
+
# @see Selector#to_s
|
222
|
+
def to_s
|
223
|
+
@namespace ? "#{@namespace}|#{@name}" : @name
|
224
|
+
end
|
225
|
+
|
226
|
+
# Unification of an element selector is somewhat complicated,
|
227
|
+
# especially when a namespace is specified.
|
228
|
+
# First, if `sel` contains another {Element} with a different \{#name},
|
229
|
+
# then the selectors can't be unified and `nil` is returned.
|
230
|
+
#
|
231
|
+
# Otherwise, if `sel` doesn't specify a namespace,
|
232
|
+
# or it specifies any namespace (via `"*"`),
|
233
|
+
# then it's returned with this element selector
|
234
|
+
# (e.g. `.foo` becomes `a.foo` or `svg|a.foo`).
|
235
|
+
# Similarly, if this selector doesn't specify a namespace,
|
236
|
+
# the namespace from `sel` is used.
|
237
|
+
#
|
238
|
+
# If both this selector *and* `sel` specify namespaces,
|
239
|
+
# those namespaces are unified via {Simple#unify_namespaces}
|
240
|
+
# and the unified namespace is used, if possible.
|
241
|
+
#
|
242
|
+
# @todo There are lots of cases that this documentation specifies;
|
243
|
+
# make sure we thoroughly test **all of them**.
|
244
|
+
# @todo Keep track of whether a default namespace has been declared
|
245
|
+
# and handle namespace-unspecified selectors accordingly.
|
246
|
+
#
|
247
|
+
# @see Selector#unify
|
248
|
+
def unify(sels)
|
249
|
+
case sels.first
|
250
|
+
when Universal;
|
251
|
+
when Element; return unless name == sels.first.name
|
252
|
+
else return [self] + sels
|
253
|
+
end
|
254
|
+
|
255
|
+
ns, accept = unify_namespaces(namespace, sels.first.namespace)
|
256
|
+
return unless accept
|
257
|
+
[Element.new(name, ns)] + sels[1..-1]
|
258
|
+
end
|
259
|
+
|
260
|
+
# @see AbstractSequence#specificity
|
261
|
+
def specificity
|
262
|
+
1
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
# An attribute selector (e.g. `[href^="http://"]`).
|
267
|
+
class Attribute < Simple
|
268
|
+
# The attribute name.
|
269
|
+
#
|
270
|
+
# @return [Array<String, Sass::Script::Tree::Node>]
|
271
|
+
attr_reader :name
|
272
|
+
|
273
|
+
# The attribute namespace. `nil` means the default namespace, `""` means
|
274
|
+
# no namespace, `"*"` means any namespace.
|
275
|
+
#
|
276
|
+
# @return [String, nil]
|
277
|
+
attr_reader :namespace
|
278
|
+
|
279
|
+
# The matching operator, e.g. `"="` or `"^="`.
|
280
|
+
#
|
281
|
+
# @return [String]
|
282
|
+
attr_reader :operator
|
283
|
+
|
284
|
+
# The right-hand side of the operator.
|
285
|
+
#
|
286
|
+
# @return [String]
|
287
|
+
attr_reader :value
|
288
|
+
|
289
|
+
# Flags for the attribute selector (e.g. `i`).
|
290
|
+
#
|
291
|
+
# @return [String]
|
292
|
+
attr_reader :flags
|
293
|
+
|
294
|
+
# @param name [String] The attribute name
|
295
|
+
# @param namespace [String, nil] See \{#namespace}
|
296
|
+
# @param operator [String] The matching operator, e.g. `"="` or `"^="`
|
297
|
+
# @param value [String] See \{#value}
|
298
|
+
# @param flags [String] See \{#flags}
|
299
|
+
# @comment
|
300
|
+
# rubocop:disable ParameterLists
|
301
|
+
def initialize(name, namespace, operator, value, flags)
|
302
|
+
# rubocop:enable ParameterLists
|
303
|
+
@name = name
|
304
|
+
@namespace = namespace
|
305
|
+
@operator = operator
|
306
|
+
@value = value
|
307
|
+
@flags = flags
|
308
|
+
end
|
309
|
+
|
310
|
+
# @see Selector#to_s
|
311
|
+
def to_s
|
312
|
+
res = "["
|
313
|
+
res << @namespace << "|" if @namespace
|
314
|
+
res << @name
|
315
|
+
res << @operator << @value if @value
|
316
|
+
res << " " << @flags if @flags
|
317
|
+
res << "]"
|
318
|
+
end
|
319
|
+
|
320
|
+
# @see AbstractSequence#specificity
|
321
|
+
def specificity
|
322
|
+
SPECIFICITY_BASE
|
323
|
+
end
|
324
|
+
end
|
325
|
+
end
|
326
|
+
end
|