haml 3.0.21 → 3.0.22

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of haml might be problematic. Click here for more details.

Files changed (195) hide show
  1. data/Rakefile +1 -41
  2. data/VERSION +1 -1
  3. data/lib/haml/precompiler.rb +8 -6
  4. data/lib/haml/template/plugin.rb +16 -6
  5. data/lib/sass/less.rb +31 -12
  6. data/lib/sass/script/funcall.rb +2 -1
  7. data/lib/sass/script/operation.rb +10 -5
  8. data/lib/sass/script/parser.rb +9 -0
  9. data/test/haml/engine_test.rb +25 -0
  10. data/test/sass/less_conversion_test.rb +24 -3
  11. data/test/sass/script_conversion_test.rb +60 -0
  12. metadata +243 -426
  13. data/vendor/sass/CONTRIBUTING +0 -3
  14. data/vendor/sass/MIT-LICENSE +0 -20
  15. data/vendor/sass/README.md +0 -201
  16. data/vendor/sass/Rakefile +0 -363
  17. data/vendor/sass/TODO +0 -39
  18. data/vendor/sass/VERSION +0 -1
  19. data/vendor/sass/VERSION_NAME +0 -1
  20. data/vendor/sass/bin/css2sass +0 -13
  21. data/vendor/sass/bin/sass +0 -8
  22. data/vendor/sass/bin/sass-convert +0 -7
  23. data/vendor/sass/doc-src/FAQ.md +0 -35
  24. data/vendor/sass/doc-src/INDENTED_SYNTAX.md +0 -210
  25. data/vendor/sass/doc-src/SASS_CHANGELOG.md +0 -1870
  26. data/vendor/sass/doc-src/SASS_REFERENCE.md +0 -1713
  27. data/vendor/sass/doc-src/SCSS_FOR_SASS_USERS.md +0 -155
  28. data/vendor/sass/ext/extconf.rb +0 -10
  29. data/vendor/sass/extra/update_watch.rb +0 -13
  30. data/vendor/sass/init.rb +0 -18
  31. data/vendor/sass/lib/sass.rb +0 -71
  32. data/vendor/sass/lib/sass/cache_store.rb +0 -208
  33. data/vendor/sass/lib/sass/callbacks.rb +0 -66
  34. data/vendor/sass/lib/sass/css.rb +0 -294
  35. data/vendor/sass/lib/sass/engine.rb +0 -792
  36. data/vendor/sass/lib/sass/environment.rb +0 -143
  37. data/vendor/sass/lib/sass/error.rb +0 -201
  38. data/vendor/sass/lib/sass/exec.rb +0 -619
  39. data/vendor/sass/lib/sass/importers.rb +0 -22
  40. data/vendor/sass/lib/sass/importers/base.rb +0 -138
  41. data/vendor/sass/lib/sass/importers/filesystem.rb +0 -121
  42. data/vendor/sass/lib/sass/less.rb +0 -363
  43. data/vendor/sass/lib/sass/plugin.rb +0 -126
  44. data/vendor/sass/lib/sass/plugin/compiler.rb +0 -346
  45. data/vendor/sass/lib/sass/plugin/configuration.rb +0 -123
  46. data/vendor/sass/lib/sass/plugin/generic.rb +0 -15
  47. data/vendor/sass/lib/sass/plugin/merb.rb +0 -48
  48. data/vendor/sass/lib/sass/plugin/rack.rb +0 -47
  49. data/vendor/sass/lib/sass/plugin/rails.rb +0 -41
  50. data/vendor/sass/lib/sass/plugin/staleness_checker.rb +0 -145
  51. data/vendor/sass/lib/sass/railtie.rb +0 -8
  52. data/vendor/sass/lib/sass/repl.rb +0 -58
  53. data/vendor/sass/lib/sass/root.rb +0 -7
  54. data/vendor/sass/lib/sass/script.rb +0 -63
  55. data/vendor/sass/lib/sass/script/bool.rb +0 -18
  56. data/vendor/sass/lib/sass/script/color.rb +0 -491
  57. data/vendor/sass/lib/sass/script/css_lexer.rb +0 -29
  58. data/vendor/sass/lib/sass/script/css_parser.rb +0 -31
  59. data/vendor/sass/lib/sass/script/funcall.rb +0 -79
  60. data/vendor/sass/lib/sass/script/functions.rb +0 -852
  61. data/vendor/sass/lib/sass/script/interpolation.rb +0 -70
  62. data/vendor/sass/lib/sass/script/lexer.rb +0 -337
  63. data/vendor/sass/lib/sass/script/literal.rb +0 -236
  64. data/vendor/sass/lib/sass/script/node.rb +0 -101
  65. data/vendor/sass/lib/sass/script/number.rb +0 -423
  66. data/vendor/sass/lib/sass/script/operation.rb +0 -92
  67. data/vendor/sass/lib/sass/script/parser.rb +0 -392
  68. data/vendor/sass/lib/sass/script/string.rb +0 -67
  69. data/vendor/sass/lib/sass/script/string_interpolation.rb +0 -93
  70. data/vendor/sass/lib/sass/script/unary_operation.rb +0 -57
  71. data/vendor/sass/lib/sass/script/variable.rb +0 -48
  72. data/vendor/sass/lib/sass/scss.rb +0 -17
  73. data/vendor/sass/lib/sass/scss/css_parser.rb +0 -51
  74. data/vendor/sass/lib/sass/scss/parser.rb +0 -838
  75. data/vendor/sass/lib/sass/scss/rx.rb +0 -126
  76. data/vendor/sass/lib/sass/scss/sass_parser.rb +0 -11
  77. data/vendor/sass/lib/sass/scss/script_lexer.rb +0 -15
  78. data/vendor/sass/lib/sass/scss/script_parser.rb +0 -25
  79. data/vendor/sass/lib/sass/scss/static_parser.rb +0 -40
  80. data/vendor/sass/lib/sass/selector.rb +0 -361
  81. data/vendor/sass/lib/sass/selector/abstract_sequence.rb +0 -62
  82. data/vendor/sass/lib/sass/selector/comma_sequence.rb +0 -82
  83. data/vendor/sass/lib/sass/selector/sequence.rb +0 -236
  84. data/vendor/sass/lib/sass/selector/simple.rb +0 -113
  85. data/vendor/sass/lib/sass/selector/simple_sequence.rb +0 -135
  86. data/vendor/sass/lib/sass/shared.rb +0 -78
  87. data/vendor/sass/lib/sass/tree/comment_node.rb +0 -128
  88. data/vendor/sass/lib/sass/tree/debug_node.rb +0 -36
  89. data/vendor/sass/lib/sass/tree/directive_node.rb +0 -75
  90. data/vendor/sass/lib/sass/tree/extend_node.rb +0 -65
  91. data/vendor/sass/lib/sass/tree/for_node.rb +0 -67
  92. data/vendor/sass/lib/sass/tree/if_node.rb +0 -81
  93. data/vendor/sass/lib/sass/tree/import_node.rb +0 -124
  94. data/vendor/sass/lib/sass/tree/mixin_def_node.rb +0 -60
  95. data/vendor/sass/lib/sass/tree/mixin_node.rb +0 -123
  96. data/vendor/sass/lib/sass/tree/node.rb +0 -490
  97. data/vendor/sass/lib/sass/tree/prop_node.rb +0 -220
  98. data/vendor/sass/lib/sass/tree/root_node.rb +0 -125
  99. data/vendor/sass/lib/sass/tree/rule_node.rb +0 -273
  100. data/vendor/sass/lib/sass/tree/variable_node.rb +0 -39
  101. data/vendor/sass/lib/sass/tree/warn_node.rb +0 -42
  102. data/vendor/sass/lib/sass/tree/while_node.rb +0 -48
  103. data/vendor/sass/lib/sass/util.rb +0 -700
  104. data/vendor/sass/lib/sass/util/subset_map.rb +0 -101
  105. data/vendor/sass/lib/sass/version.rb +0 -109
  106. data/vendor/sass/rails/init.rb +0 -1
  107. data/vendor/sass/sass.gemspec +0 -32
  108. data/vendor/sass/test/sass/cache_test.rb +0 -74
  109. data/vendor/sass/test/sass/callbacks_test.rb +0 -61
  110. data/vendor/sass/test/sass/conversion_test.rb +0 -1210
  111. data/vendor/sass/test/sass/css2sass_test.rb +0 -364
  112. data/vendor/sass/test/sass/data/hsl-rgb.txt +0 -319
  113. data/vendor/sass/test/sass/engine_test.rb +0 -2283
  114. data/vendor/sass/test/sass/extend_test.rb +0 -1348
  115. data/vendor/sass/test/sass/functions_test.rb +0 -565
  116. data/vendor/sass/test/sass/importer_test.rb +0 -104
  117. data/vendor/sass/test/sass/less_conversion_test.rb +0 -632
  118. data/vendor/sass/test/sass/mock_importer.rb +0 -49
  119. data/vendor/sass/test/sass/more_results/more1.css +0 -9
  120. data/vendor/sass/test/sass/more_results/more1_with_line_comments.css +0 -26
  121. data/vendor/sass/test/sass/more_results/more_import.css +0 -29
  122. data/vendor/sass/test/sass/more_templates/_more_partial.sass +0 -2
  123. data/vendor/sass/test/sass/more_templates/more1.sass +0 -23
  124. data/vendor/sass/test/sass/more_templates/more_import.sass +0 -11
  125. data/vendor/sass/test/sass/plugin_test.rb +0 -430
  126. data/vendor/sass/test/sass/results/alt.css +0 -4
  127. data/vendor/sass/test/sass/results/basic.css +0 -9
  128. data/vendor/sass/test/sass/results/compact.css +0 -5
  129. data/vendor/sass/test/sass/results/complex.css +0 -86
  130. data/vendor/sass/test/sass/results/compressed.css +0 -1
  131. data/vendor/sass/test/sass/results/expanded.css +0 -19
  132. data/vendor/sass/test/sass/results/import.css +0 -31
  133. data/vendor/sass/test/sass/results/line_numbers.css +0 -49
  134. data/vendor/sass/test/sass/results/mixins.css +0 -95
  135. data/vendor/sass/test/sass/results/multiline.css +0 -24
  136. data/vendor/sass/test/sass/results/nested.css +0 -22
  137. data/vendor/sass/test/sass/results/options.css +0 -1
  138. data/vendor/sass/test/sass/results/parent_ref.css +0 -13
  139. data/vendor/sass/test/sass/results/script.css +0 -16
  140. data/vendor/sass/test/sass/results/scss_import.css +0 -31
  141. data/vendor/sass/test/sass/results/scss_importee.css +0 -2
  142. data/vendor/sass/test/sass/results/subdir/nested_subdir/nested_subdir.css +0 -1
  143. data/vendor/sass/test/sass/results/subdir/subdir.css +0 -3
  144. data/vendor/sass/test/sass/results/units.css +0 -11
  145. data/vendor/sass/test/sass/results/warn.css +0 -0
  146. data/vendor/sass/test/sass/results/warn_imported.css +0 -0
  147. data/vendor/sass/test/sass/script_conversion_test.rb +0 -254
  148. data/vendor/sass/test/sass/script_test.rb +0 -470
  149. data/vendor/sass/test/sass/scss/css_test.rb +0 -897
  150. data/vendor/sass/test/sass/scss/rx_test.rb +0 -156
  151. data/vendor/sass/test/sass/scss/scss_test.rb +0 -1088
  152. data/vendor/sass/test/sass/scss/test_helper.rb +0 -37
  153. data/vendor/sass/test/sass/templates/_partial.sass +0 -2
  154. data/vendor/sass/test/sass/templates/alt.sass +0 -16
  155. data/vendor/sass/test/sass/templates/basic.sass +0 -23
  156. data/vendor/sass/test/sass/templates/bork1.sass +0 -2
  157. data/vendor/sass/test/sass/templates/bork2.sass +0 -2
  158. data/vendor/sass/test/sass/templates/bork3.sass +0 -2
  159. data/vendor/sass/test/sass/templates/bork4.sass +0 -2
  160. data/vendor/sass/test/sass/templates/compact.sass +0 -17
  161. data/vendor/sass/test/sass/templates/complex.sass +0 -305
  162. data/vendor/sass/test/sass/templates/compressed.sass +0 -15
  163. data/vendor/sass/test/sass/templates/expanded.sass +0 -17
  164. data/vendor/sass/test/sass/templates/import.sass +0 -12
  165. data/vendor/sass/test/sass/templates/importee.less +0 -2
  166. data/vendor/sass/test/sass/templates/importee.sass +0 -19
  167. data/vendor/sass/test/sass/templates/line_numbers.sass +0 -13
  168. data/vendor/sass/test/sass/templates/mixin_bork.sass +0 -5
  169. data/vendor/sass/test/sass/templates/mixins.sass +0 -76
  170. data/vendor/sass/test/sass/templates/multiline.sass +0 -20
  171. data/vendor/sass/test/sass/templates/nested.sass +0 -25
  172. data/vendor/sass/test/sass/templates/nested_bork1.sass +0 -2
  173. data/vendor/sass/test/sass/templates/nested_bork2.sass +0 -2
  174. data/vendor/sass/test/sass/templates/nested_bork3.sass +0 -2
  175. data/vendor/sass/test/sass/templates/nested_bork4.sass +0 -2
  176. data/vendor/sass/test/sass/templates/nested_mixin_bork.sass +0 -6
  177. data/vendor/sass/test/sass/templates/options.sass +0 -2
  178. data/vendor/sass/test/sass/templates/parent_ref.sass +0 -25
  179. data/vendor/sass/test/sass/templates/script.sass +0 -101
  180. data/vendor/sass/test/sass/templates/scss_import.scss +0 -11
  181. data/vendor/sass/test/sass/templates/scss_importee.scss +0 -1
  182. data/vendor/sass/test/sass/templates/subdir/nested_subdir/_nested_partial.sass +0 -2
  183. data/vendor/sass/test/sass/templates/subdir/nested_subdir/nested_subdir.sass +0 -3
  184. data/vendor/sass/test/sass/templates/subdir/subdir.sass +0 -6
  185. data/vendor/sass/test/sass/templates/units.sass +0 -11
  186. data/vendor/sass/test/sass/templates/warn.sass +0 -3
  187. data/vendor/sass/test/sass/templates/warn_imported.sass +0 -4
  188. data/vendor/sass/test/sass/test_helper.rb +0 -8
  189. data/vendor/sass/test/sass/util/subset_map_test.rb +0 -91
  190. data/vendor/sass/test/sass/util_test.rb +0 -275
  191. data/vendor/sass/test/test_helper.rb +0 -64
  192. data/vendor/sass/yard/callbacks.rb +0 -29
  193. data/vendor/sass/yard/default/fulldoc/html/css/common.sass +0 -26
  194. data/vendor/sass/yard/default/layout/html/footer.erb +0 -12
  195. data/vendor/sass/yard/inherited_hash.rb +0 -41
@@ -1,62 +0,0 @@
1
- module Sass
2
- module Selector
3
- # The abstract parent class of the various selector sequence classes.
4
- #
5
- # All subclasses should implement a `members` method
6
- # that returns an array of object that respond to `#line=` and `#filename=`.
7
- class AbstractSequence
8
- # The line of the Sass template on which this selector was declared.
9
- #
10
- # @return [Fixnum]
11
- attr_reader :line
12
-
13
- # The name of the file in which this selector was declared.
14
- #
15
- # @return [String, nil]
16
- attr_reader :filename
17
-
18
- # Sets the line of the Sass template on which this selector was declared.
19
- # This also sets the line for all child selectors.
20
- #
21
- # @param line [Fixnum]
22
- # @return [Fixnum]
23
- def line=(line)
24
- members.each {|m| m.line = line}
25
- @line = line
26
- end
27
-
28
- # Sets the name of the file in which this selector was declared,
29
- # or `nil` if it was not declared in a file (e.g. on stdin).
30
- # This also sets the filename for all child selectors.
31
- #
32
- # @param filename [String, nil]
33
- # @return [String, nil]
34
- def filename=(filename)
35
- members.each {|m| m.filename = filename}
36
- @filename = filename
37
- end
38
-
39
- # Returns a hash code for this sequence.
40
- #
41
- # Subclasses should define `#_hash` rather than overriding this method,
42
- # which automatically handles memoizing the result.
43
- #
44
- # @return [Fixnum]
45
- def hash
46
- @_hash ||= _hash
47
- end
48
-
49
- # Checks equality between this and another object.
50
- #
51
- # Subclasses should define `#_eql?` rather than overriding this method,
52
- # which handles checking class equality and hash equality.
53
- #
54
- # @param other [Object] The object to test equality against
55
- # @return [Boolean] Whether or not this is equal to `other`
56
- def eql?(other)
57
- other.class == self.class && other.hash == self.hash && _eql?(other)
58
- end
59
- alias_method :==, :eql?
60
- end
61
- end
62
- end
@@ -1,82 +0,0 @@
1
- module Sass
2
- module Selector
3
- # A comma-separated sequence of selectors.
4
- class CommaSequence < AbstractSequence
5
- # The comma-separated selector sequences
6
- # represented by this class.
7
- #
8
- # @return [Array<Sequence>]
9
- attr_reader :members
10
-
11
- # @param seqs [Array<Sequence>] See \{#members}
12
- def initialize(seqs)
13
- @members = seqs
14
- end
15
-
16
- # Resolves the {Parent} selectors within this selector
17
- # by replacing them with the given parent selector,
18
- # handling commas appropriately.
19
- #
20
- # @param super_cseq [CommaSequence] The parent selector
21
- # @return [CommaSequence] This selector, with parent references resolved
22
- # @raise [Sass::SyntaxError] If a parent selector is invalid
23
- def resolve_parent_refs(super_cseq)
24
- if super_cseq.nil?
25
- if @members.any? do |sel|
26
- sel.members.any? do |sel_or_op|
27
- sel_or_op.is_a?(SimpleSequence) && sel_or_op.members.any? {|ssel| ssel.is_a?(Parent)}
28
- end
29
- end
30
- raise Sass::SyntaxError.new("Base-level rules cannot contain the parent-selector-referencing character '&'.")
31
- end
32
- return self
33
- end
34
-
35
- CommaSequence.new(
36
- super_cseq.members.map do |super_seq|
37
- @members.map {|seq| seq.resolve_parent_refs(super_seq)}
38
- end.flatten)
39
- end
40
-
41
- # Non-destrucively extends this selector
42
- # with the extensions specified in a hash
43
- # (which should be populated via {Sass::Tree::Node#cssize}).
44
- #
45
- # @todo Link this to the reference documentation on `@extend`
46
- # when such a thing exists.
47
- #
48
- # @param extends [Sass::Util::SubsetMap{Selector::Simple => Selector::Sequence}]
49
- # The extensions to perform on this selector
50
- # @return [CommaSequence] A copy of this selector,
51
- # with extensions made according to `extends`
52
- def do_extend(extends)
53
- CommaSequence.new(members.map {|seq| seq.do_extend(extends)}.flatten)
54
- end
55
-
56
- # Returns a string representation of the sequence.
57
- # This is basically the selector string.
58
- #
59
- # @return [String]
60
- def inspect
61
- members.map {|m| m.inspect}.join(", ")
62
- end
63
-
64
- # @see Simple#to_a
65
- def to_a
66
- arr = Sass::Util.intersperse(@members.map {|m| m.to_a}, ", ").flatten
67
- arr.delete("\n")
68
- arr
69
- end
70
-
71
- private
72
-
73
- def _hash
74
- members.hash
75
- end
76
-
77
- def _eql?(other)
78
- other.class == self.class && other.members.eql?(self.members)
79
- end
80
- end
81
- end
82
- end
@@ -1,236 +0,0 @@
1
- module Sass
2
- module Selector
3
- # An operator-separated sequence of
4
- # {SimpleSequence simple selector sequences}.
5
- class Sequence < AbstractSequence
6
- # Sets the line of the Sass template on which this selector was declared.
7
- # This also sets the line for all child selectors.
8
- #
9
- # @param line [Fixnum]
10
- # @return [Fixnum]
11
- def line=(line)
12
- members.each {|m| m.line = line if m.is_a?(SimpleSequence)}
13
- line
14
- end
15
-
16
- # Sets the name of the file in which this selector was declared,
17
- # or `nil` if it was not declared in a file (e.g. on stdin).
18
- # This also sets the filename for all child selectors.
19
- #
20
- # @param filename [String, nil]
21
- # @return [String, nil]
22
- def filename=(filename)
23
- members.each {|m| m.filename = filename if m.is_a?(SimpleSequence)}
24
- filename
25
- end
26
-
27
- # The array of {SimpleSequence simple selector sequences}, operators, and newlines.
28
- # The operators are strings such as `"+"` and `">"`
29
- # representing the corresponding CSS operators.
30
- # Newlines are also newline strings;
31
- # these aren't semantically relevant,
32
- # but they do affect formatting.
33
- #
34
- # @return [Array<SimpleSequence, String>]
35
- attr_reader :members
36
-
37
- # @param seqs_and_ops [Array<SimpleSequence, String>] See \{#members}
38
- def initialize(seqs_and_ops)
39
- @members = seqs_and_ops
40
- end
41
-
42
- # Resolves the {Parent} selectors within this selector
43
- # by replacing them with the given parent selector,
44
- # handling commas appropriately.
45
- #
46
- # @param super_seq [Sequence] The parent selector sequence
47
- # @return [Sequence] This selector, with parent references resolved
48
- # @raise [Sass::SyntaxError] If a parent selector is invalid
49
- def resolve_parent_refs(super_seq)
50
- members = @members
51
- members.slice!(0) if nl = (members.first == "\n")
52
- unless members.any? do |seq_or_op|
53
- seq_or_op.is_a?(SimpleSequence) && seq_or_op.members.first.is_a?(Parent)
54
- end
55
- members = []
56
- members << "\n" if nl
57
- members << SimpleSequence.new([Parent.new])
58
- members += @members
59
- end
60
-
61
- Sequence.new(
62
- members.map do |seq_or_op|
63
- next seq_or_op unless seq_or_op.is_a?(SimpleSequence)
64
- seq_or_op.resolve_parent_refs(super_seq)
65
- end.flatten)
66
- end
67
-
68
- # Non-destructively extends this selector
69
- # with the extensions specified in a hash
70
- # (which should be populated via {Sass::Tree::Node#cssize}).
71
- #
72
- # @overload def do_extend(extends)
73
- # @param extends [Sass::Util::SubsetMap{Selector::Simple => Selector::Sequence}]
74
- # The extensions to perform on this selector
75
- # @return [Array<Sequence>] A list of selectors generated
76
- # by extending this selector with `extends`.
77
- # These correspond to a {CommaSequence}'s {CommaSequence#members members array}.
78
- # @see CommaSequence#do_extend
79
- def do_extend(extends, seen = Set.new)
80
- paths = Sass::Util.paths(members.map do |sseq_or_op|
81
- next [[sseq_or_op]] unless sseq_or_op.is_a?(SimpleSequence)
82
- extended = sseq_or_op.do_extend(extends, seen)
83
- choices = extended.map {|seq| seq.members}
84
- choices.unshift([sseq_or_op]) unless extended.any? {|seq| seq.superselector?(sseq_or_op)}
85
- choices
86
- end)
87
- Sass::Util.flatten(paths.map {|path| weave(path)}, 1).map {|p| Sequence.new(p)}
88
- end
89
-
90
- # Returns whether or not this selector matches all elements
91
- # that the given selector matches (as well as possibly more).
92
- #
93
- # @example
94
- # (.foo).superselector?(.foo.bar) #=> true
95
- # (.foo).superselector?(.bar) #=> false
96
- # (.bar .foo).superselector?(.foo) #=> false
97
- # @param sseq [SimpleSequence]
98
- # @return [Boolean]
99
- def superselector?(sseq)
100
- return false unless members.size == 1
101
- members.last.superselector?(sseq)
102
- end
103
-
104
- # @see Simple#to_a
105
- def to_a
106
- ary = @members.map {|seq_or_op| seq_or_op.is_a?(SimpleSequence) ? seq_or_op.to_a : seq_or_op}
107
- ary = Sass::Util.intersperse(ary, " ")
108
- ary = Sass::Util.substitute(ary, [" ", "\n", " "], ["\n"])
109
- ary.flatten.compact
110
- end
111
-
112
- # Returns a string representation of the sequence.
113
- # This is basically the selector string.
114
- #
115
- # @return [String]
116
- def inspect
117
- members.map {|m| m.inspect}.join(" ")
118
- end
119
-
120
- private
121
-
122
- # Conceptually, this expands "parenthesized selectors".
123
- # That is, if we have `.A .B {@extend .C}` and `.D .C {...}`,
124
- # this conceptually expands into `.D .C, .D (.A .B)`,
125
- # and this function translates `.D (.A .B)` into `.D .A .B, .A.D .B, .D .A .B`.
126
- #
127
- # @param path [Array<Array<SimpleSequence or String>>] A list of parenthesized selector groups.
128
- # @return [Array<Array<SimpleSequence or String>>] A list of fully-expanded selectors.
129
- def weave(path)
130
- befores = [[]]
131
- afters = path.dup
132
-
133
- until afters.empty?
134
- current = afters.shift.dup
135
- last_current = [current.pop]
136
- while !current.empty? && last_current.first.is_a?(String) || current.last.is_a?(String)
137
- last_current.unshift(current.pop)
138
- end
139
- befores = Sass::Util.flatten(befores.map do |before|
140
- subweave(before, current).map {|seqs| seqs + last_current}
141
- end, 1)
142
- return befores if afters.empty?
143
- end
144
- end
145
-
146
- # This interweaves two lists of selectors,
147
- # returning all possible orderings of them (including using unification)
148
- # that maintain the relative ordering of the input arrays.
149
- #
150
- # For example, given `.foo .bar` and `.baz .bang`,
151
- # this would return `.foo .bar .baz .bang`, `.foo .bar.baz .bang`,
152
- # `.foo .baz .bar .bang`, `.foo .baz .bar.bang`, `.foo .baz .bang .bar`,
153
- # and so on until `.baz .bang .foo .bar`.
154
- #
155
- # @overload def subweave(seq1, seq2)
156
- # @param seq1 [Array<SimpleSequence or String>]
157
- # @param seq2 [Array<SimpleSequence or String>]
158
- # @return [Array<Array<SimpleSequence or String>>]
159
- def subweave(seq1, seq2, cache = {})
160
- return [seq2] if seq1.empty?
161
- return [seq1] if seq2.empty?
162
-
163
- seq1 = group_selectors(seq1)
164
- seq2 = group_selectors(seq2)
165
- lcs = Sass::Util.lcs(seq2, seq1) do |s1, s2|
166
- next s1 if s1 == s2
167
- next unless s1.first.is_a?(SimpleSequence) && s2.first.is_a?(SimpleSequence)
168
- next s2 if subweave_superselector?(s1, s2)
169
- next s1 if subweave_superselector?(s2, s1)
170
- end
171
-
172
- diff = []
173
- until lcs.empty?
174
- diff << chunks(seq1, seq2) {|s| subweave_superselector?(s.first, lcs.first)} << [lcs.shift]
175
- seq1.shift
176
- seq2.shift
177
- end
178
- diff << chunks(seq1, seq2) {|s| s.empty?}
179
- diff.reject! {|c| c.empty?}
180
-
181
- Sass::Util.paths(diff).map {|p| p.flatten}
182
- end
183
-
184
- def chunks(seq1, seq2)
185
- chunk1 = []
186
- chunk1 << seq1.shift until yield seq1
187
- chunk2 = []
188
- chunk2 << seq2.shift until yield seq2
189
- return [] if chunk1.empty? && chunk2.empty?
190
- return [chunk2] if chunk1.empty?
191
- return [chunk1] if chunk2.empty?
192
- [chunk1 + chunk2, chunk2 + chunk1]
193
- end
194
-
195
- def group_selectors(seq)
196
- newseq = []
197
- tail = seq.dup
198
- until tail.empty?
199
- head = []
200
- begin
201
- head << tail.shift
202
- end while !tail.empty? && head.last.is_a?(String) || tail.first.is_a?(String)
203
- newseq << head
204
- end
205
- return newseq
206
- end
207
-
208
- def subweave_superselector?(sseq1, sseq2)
209
- if sseq1.size > 1
210
- # More complex selectors are never superselectors of less complex ones
211
- return unless sseq2.size > 1
212
- # .foo ~ .bar is a superselector of .foo + .bar
213
- return unless sseq1[1] == "~" ? sseq2[1] != ">" : sseq2[1] == sseq1[1]
214
- return unless sseq1.first.superselector?(sseq2.first)
215
- return true if sseq1.size == 2
216
- return false if sseq2.size == 2
217
- return subweave_superselector?(sseq1[2..-1], sseq2[2..-1])
218
- elsif sseq2.size > 1
219
- return true if sseq2[1] == ">" && sseq1.first.superselector?(sseq2.first)
220
- return false if sseq2.size == 2
221
- return subweave_superselector?(sseq1, sseq2[2..-1])
222
- else
223
- sseq1.first.superselector?(sseq2.first)
224
- end
225
- end
226
-
227
- def _hash
228
- members.reject {|m| m == "\n"}.hash
229
- end
230
-
231
- def _eql?(other)
232
- other.members.reject {|m| m == "\n"}.eql?(self.members.reject {|m| m == "\n"})
233
- end
234
- end
235
- end
236
- end
@@ -1,113 +0,0 @@
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
- # Returns a representation of the node
18
- # as an array of strings and potentially {Sass::Script::Node}s
19
- # (if there's interpolation in the selector).
20
- # When the interpolation is resolved and the strings are joined together,
21
- # this will be the string representation of this node.
22
- #
23
- # @return [Array<String, Sass::Script::Node>]
24
- def to_a
25
- Sass::Util.abstract(self)
26
- end
27
-
28
- # Returns a string representation of the node.
29
- # This is basically the selector string.
30
- #
31
- # @return [String]
32
- def inspect
33
- to_a.map {|e| e.is_a?(Sass::Script::Node) ? "\#{#{e.to_sass}}" : e}.join
34
- end
35
-
36
- # Returns a hash code for this selector object.
37
- #
38
- # By default, this is based on the value of \{#to\_a},
39
- # so if that contains information irrelevant to the identity of the selector,
40
- # this should be overridden.
41
- #
42
- # @return [Fixnum]
43
- def hash
44
- @_hash ||= to_a.hash
45
- end
46
-
47
- # Checks equality between this and another object.
48
- #
49
- # By default, this is based on the value of \{#to\_a},
50
- # so if that contains information irrelevant to the identity of the selector,
51
- # this should be overridden.
52
- #
53
- # @param other [Object] The object to test equality against
54
- # @return [Boolean] Whether or not this is equal to `other`
55
- def eql?(other)
56
- other.class == self.class && other.hash == self.hash && other.to_a.eql?(to_a)
57
- end
58
- alias_method :==, :eql?
59
-
60
- # Unifies this selector with a {SimpleSequence}'s {SimpleSequence#members members array},
61
- # returning another `SimpleSequence` members array
62
- # that matches both this selector and the input selector.
63
- #
64
- # By default, this just appends this selector to the end of the array
65
- # (or returns the original array if this selector already exists in it).
66
- #
67
- # @param sels [Array<Simple>] A {SimpleSequence}'s {SimpleSequence#members members array}
68
- # @return [Array<Simple>, nil] A {SimpleSequence} {SimpleSequence#members members array}
69
- # matching both `sels` and this selector,
70
- # or `nil` if this is impossible (e.g. unifying `#foo` and `#bar`)
71
- # @raise [Sass::SyntaxError] If this selector cannot be unified.
72
- # This will only ever occur when a dynamic selector,
73
- # such as {Parent} or {Interpolation}, is used in unification.
74
- # Since these selectors should be resolved
75
- # by the time extension and unification happen,
76
- # this exception will only ever be raised as a result of programmer error
77
- def unify(sels)
78
- return sels if sels.any? {|sel2| eql?(sel2)}
79
- sels_with_ix = Sass::Util.enum_with_index(sels)
80
- _, i =
81
- if self.is_a?(Pseudo) || self.is_a?(SelectorPseudoClass)
82
- sels_with_ix.find {|sel, _| sel.is_a?(Pseudo) && sels.last.type == :element}
83
- else
84
- sels_with_ix.find {|sel, _| sel.is_a?(Pseudo) || sel.is_a?(SelectorPseudoClass)}
85
- end
86
- return sels + [self] unless i
87
- return sels[0...i] + [self] + sels[i..-1]
88
- end
89
-
90
- protected
91
-
92
- # Unifies two namespaces,
93
- # returning a namespace that works for both of them if possible.
94
- #
95
- # @param ns1 [String, nil] The first namespace.
96
- # `nil` means none specified, e.g. `foo`.
97
- # The empty string means no namespace specified, e.g. `|foo`.
98
- # `"*"` means any namespace is allowed, e.g. `*|foo`.
99
- # @param ns2 [String, nil] The second namespace. See `ns1`.
100
- # @return [Array(String or nil, Boolean)]
101
- # The first value is the unified namespace, or `nil` for no namespace.
102
- # The second value is whether or not a namespace that works for both inputs
103
- # could be found at all.
104
- # If the second value is `false`, the first should be ignored.
105
- def unify_namespaces(ns1, ns2)
106
- return nil, false unless ns1 == ns2 || ns1.nil? || ns1 == ['*'] || ns2.nil? || ns2 == ['*']
107
- return ns2, true if ns1 == ['*']
108
- return ns1, true if ns2 == ['*']
109
- return ns1 || ns2, true
110
- end
111
- end
112
- end
113
- end