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,490 +0,0 @@
1
- module Sass
2
- # A namespace for nodes in the Sass parse tree.
3
- #
4
- # The Sass parse tree has three states: dynamic, static Sass, and static CSS.
5
- #
6
- # When it's first parsed, a Sass document is in the dynamic state.
7
- # It has nodes for mixin definitions and `@for` loops and so forth,
8
- # in addition to nodes for CSS rules and properties.
9
- # Nodes that only appear in this state are called **dynamic nodes**.
10
- #
11
- # {Tree::Node#perform} returns a static Sass tree, which is different.
12
- # It still has nodes for CSS rules and properties
13
- # but it doesn't have any dynamic-generation-related nodes.
14
- # The nodes in this state are in the same structure as the Sass document:
15
- # rules and properties are nested beneath one another.
16
- # Nodes that can be in this state or in the dynamic state
17
- # are called **static nodes**.
18
- #
19
- # {Tree::Node#cssize} then returns a static CSS tree.
20
- # This is like a static Sass tree,
21
- # but the structure exactly mirrors that of the generated CSS.
22
- # Rules and properties can't be nested beneath one another in this state.
23
- #
24
- # Finally, {Tree::Node#to_s} can be called on a static CSS tree
25
- # to get the actual CSS code as a string.
26
- module Tree
27
- # The abstract superclass of all parse-tree nodes.
28
- class Node
29
- include Enumerable
30
-
31
- # The child nodes of this node.
32
- #
33
- # @return [Array<Tree::Node>]
34
- attr_accessor :children
35
-
36
- # Whether or not this node has child nodes.
37
- # This may be true even when \{#children} is empty,
38
- # in which case this node has an empty block (e.g. `{}`).
39
- #
40
- # @return [Boolean]
41
- attr_accessor :has_children
42
-
43
- # The line of the document on which this node appeared.
44
- #
45
- # @return [Fixnum]
46
- attr_accessor :line
47
-
48
- # The name of the document on which this node appeared.
49
- #
50
- # @return [String]
51
- attr_writer :filename
52
-
53
- # The options hash for the node.
54
- # See {file:SASS_REFERENCE.md#sass_options the Sass options documentation}.
55
- #
56
- # @return [{Symbol => Object}]
57
- attr_reader :options
58
-
59
- def initialize
60
- @children = []
61
- end
62
-
63
- # Sets the options hash for the node and all its children.
64
- #
65
- # @param options [{Symbol => Object}] The options
66
- # @see #options
67
- def options=(options)
68
- children.each {|c| c.options = options}
69
- @options = options
70
- end
71
-
72
- # @private
73
- def children=(children)
74
- self.has_children ||= !children.empty?
75
- @children = children
76
- end
77
-
78
- # The name of the document on which this node appeared.
79
- #
80
- # @return [String]
81
- def filename
82
- @filename || (@options && @options[:filename])
83
- end
84
-
85
- # Appends a child to the node.
86
- #
87
- # @param child [Tree::Node, Array<Tree::Node>] The child node or nodes
88
- # @raise [Sass::SyntaxError] if `child` is invalid
89
- # @see #invalid_child?
90
- def <<(child)
91
- return if child.nil?
92
- if child.is_a?(Array)
93
- child.each {|c| self << c}
94
- else
95
- check_child! child
96
- self.has_children = true
97
- @children << child
98
- end
99
- end
100
-
101
- # Raises an error if the given child node is invalid.
102
- #
103
- # @param child [Tree::Node] The child node
104
- # @raise [Sass::SyntaxError] if `child` is invalid
105
- # @see #invalid_child?
106
- def check_child!(child)
107
- if msg = invalid_child?(child)
108
- raise Sass::SyntaxError.new(msg, :line => child.line)
109
- end
110
- end
111
-
112
- # Compares this node and another object (only other {Tree::Node}s will be equal).
113
- # This does a structural comparison;
114
- # if the contents of the nodes and all the child nodes are equivalent,
115
- # then the nodes are as well.
116
- #
117
- # Only static nodes need to override this.
118
- #
119
- # @param other [Object] The object to compare with
120
- # @return [Boolean] Whether or not this node and the other object
121
- # are the same
122
- # @see Sass::Tree
123
- def ==(other)
124
- self.class == other.class && other.children == children
125
- end
126
-
127
- # True if \{#to\_s} will return `nil`;
128
- # that is, if the node shouldn't be rendered.
129
- # Should only be called in a static tree.
130
- #
131
- # @return [Boolean]
132
- def invisible?; false; end
133
-
134
- # The output style. See {file:SASS_REFERENCE.md#sass_options the Sass options documentation}.
135
- #
136
- # @return [Symbol]
137
- def style
138
- @options[:style]
139
- end
140
-
141
- # Computes the CSS corresponding to this static CSS tree.
142
- #
143
- # \{#to_s} shouldn't be overridden directly; instead, override \{#\_to\_s}.
144
- # Only static-node subclasses need to implement \{#to\_s}.
145
- #
146
- # This may return `nil`, but it will only do so if \{#invisible?} is true.
147
- #
148
- # @param args [Array] Passed on to \{#\_to\_s}
149
- # @return [String, nil] The resulting CSS
150
- # @see Sass::Tree
151
- def to_s(*args)
152
- _to_s(*args)
153
- rescue Sass::SyntaxError => e
154
- e.modify_backtrace(:filename => filename, :line => line)
155
- raise e
156
- end
157
-
158
- # Converts a static CSS tree (e.g. the output of \{#cssize})
159
- # into another static CSS tree,
160
- # with the given extensions applied to all relevant {RuleNode}s.
161
- #
162
- # @todo Link this to the reference documentation on `@extend`
163
- # when such a thing exists.
164
- #
165
- # @param extends [Sass::Util::SubsetMap{Selector::Simple => Selector::Sequence}]
166
- # The extensions to perform on this tree
167
- # @return [Tree::Node] The resulting tree of static CSS nodes.
168
- # @raise [Sass::SyntaxError] Only if there's a programmer error
169
- # and this is not a static CSS tree
170
- def do_extend(extends)
171
- node = dup
172
- node.children = children.map {|c| c.do_extend(extends)}
173
- node
174
- rescue Sass::SyntaxError => e
175
- e.modify_backtrace(:filename => filename, :line => line)
176
- raise e
177
- end
178
-
179
- # Converts a static Sass tree (e.g. the output of \{#perform})
180
- # into a static CSS tree.
181
- #
182
- # \{#cssize} shouldn't be overridden directly;
183
- # instead, override \{#\_cssize} or \{#cssize!}.
184
- #
185
- # @param extends [Sass::Util::SubsetMap{Selector::Simple => Selector::Sequence}]
186
- # The extensions defined for this tree
187
- # @param parent [Node, nil] The parent node of this node.
188
- # This should only be non-nil if the parent is the same class as this node
189
- # @return [Tree::Node] The resulting tree of static nodes
190
- # @raise [Sass::SyntaxError] if some element of the tree is invalid
191
- # @see Sass::Tree
192
- def cssize(extends, parent = nil)
193
- _cssize(extends, (parent if parent.class == self.class))
194
- rescue Sass::SyntaxError => e
195
- e.modify_backtrace(:filename => filename, :line => line)
196
- raise e
197
- end
198
-
199
- # Converts a dynamic tree into a static Sass tree.
200
- # That is, runs the dynamic Sass code:
201
- # mixins, variables, control directives, and so forth.
202
- # This doesn't modify this node or any of its children.
203
- #
204
- # \{#perform} shouldn't be overridden directly;
205
- # instead, override \{#\_perform} or \{#perform!}.
206
- #
207
- # @param environment [Sass::Environment] The lexical environment containing
208
- # variable and mixin values
209
- # @return [Tree::Node] The resulting tree of static nodes
210
- # @raise [Sass::SyntaxError] if some element of the tree is invalid
211
- # @see Sass::Tree
212
- def perform(environment)
213
- _perform(environment)
214
- rescue Sass::SyntaxError => e
215
- e.modify_backtrace(:filename => filename, :line => line)
216
- raise e
217
- end
218
-
219
- # Iterates through each node in the tree rooted at this node
220
- # in a pre-order walk.
221
- #
222
- # @yield node
223
- # @yieldparam node [Node] a node in the tree
224
- def each(&block)
225
- yield self
226
- children.each {|c| c.each(&block)}
227
- end
228
-
229
- # Converts a node to Sass code that will generate it.
230
- #
231
- # @param tabs [Fixnum] The amount of tabulation to use for the Sass code
232
- # @param opts [{Symbol => Object}] An options hash (see {Sass::CSS#initialize})
233
- # @return [String] The Sass code corresponding to the node
234
- def to_sass(tabs = 0, opts = {})
235
- to_src(tabs, opts, :sass)
236
- end
237
-
238
- # Converts a node to SCSS code that will generate it.
239
- #
240
- # @param tabs [Fixnum] The amount of tabulation to use for the SCSS code
241
- # @param opts [{Symbol => Object}] An options hash (see {Sass::CSS#initialize})
242
- # @return [String] The Sass code corresponding to the node
243
- def to_scss(tabs = 0, opts = {})
244
- to_src(tabs, opts, :scss)
245
- end
246
-
247
- # Names of options that are saved when the node is serialized and cached.
248
- SAVED_OPTIONS = [:importer]
249
-
250
- # Ensures that only {SAVED_OPTIONS} get saved.
251
- def _around_dump
252
- old_options = @options
253
- old_children = @children
254
- @options = {}
255
- SAVED_OPTIONS.each do |opt|
256
- @options[opt] = old_options[opt]
257
- end
258
- @options = Sass::Util.dump(@options)
259
- @children = Sass::Util.dump(@children)
260
- yield
261
- ensure
262
- @options = old_options
263
- @children = old_children
264
- end
265
-
266
- # Ensures that only {SAVED_OPTIONS} get saved.
267
- def _after_load
268
- @options = Sass::Util.load(@options)
269
- @children = Sass::Util.load(@children)
270
- end
271
-
272
- protected
273
-
274
- # Computes the CSS corresponding to this particular Sass node.
275
- #
276
- # This method should never raise {Sass::SyntaxError}s.
277
- # Such errors will not be properly annotated with Sass backtrace information.
278
- # All error conditions should be checked in earlier transformations,
279
- # such as \{#cssize} and \{#perform}.
280
- #
281
- # @param args [Array] ignored
282
- # @return [String, nil] The resulting CSS
283
- # @see #to_s
284
- # @see Sass::Tree
285
- def _to_s
286
- Sass::Util.abstract(self)
287
- end
288
-
289
- # Converts this static Sass node into a static CSS node,
290
- # returning the new node.
291
- # This doesn't modify this node or any of its children.
292
- #
293
- # @param extends [Sass::Util::SubsetMap{Selector::Simple => Selector::Sequence}]
294
- # The extensions defined for this tree
295
- # @param parent [Node, nil] The parent node of this node.
296
- # This should only be non-nil if the parent is the same class as this node
297
- # @return [Tree::Node, Array<Tree::Node>] The resulting static CSS nodes
298
- # @raise [Sass::SyntaxError] if some element of the tree is invalid
299
- # @see #cssize
300
- # @see Sass::Tree
301
- def _cssize(extends, parent)
302
- node = dup
303
- node.cssize!(extends, parent)
304
- node
305
- end
306
-
307
- # Destructively converts this static Sass node into a static CSS node.
308
- # This *does* modify this node,
309
- # but will be run non-destructively by \{#\_cssize\}.
310
- #
311
- # @param extends [Sass::Util::SubsetMap{Selector::Simple => Selector::Sequence}]
312
- # The extensions defined for this tree
313
- # @param parent [Node, nil] The parent node of this node.
314
- # This should only be non-nil if the parent is the same class as this node
315
- # @see #cssize
316
- def cssize!(extends, parent)
317
- self.children = children.map {|c| c.cssize(extends, self)}.flatten
318
- end
319
-
320
- # Runs any dynamic Sass code in this particular node.
321
- # This doesn't modify this node or any of its children.
322
- #
323
- # @param environment [Sass::Environment] The lexical environment containing
324
- # variable and mixin values
325
- # @return [Tree::Node, Array<Tree::Node>] The resulting static nodes
326
- # @see #perform
327
- # @see Sass::Tree
328
- def _perform(environment)
329
- node = dup
330
- node.perform!(environment)
331
- node
332
- end
333
-
334
- # Destructively runs dynamic Sass code in this particular node.
335
- # This *does* modify this node,
336
- # but will be run non-destructively by \{#\_perform\}.
337
- #
338
- # @param environment [Sass::Environment] The lexical environment containing
339
- # variable and mixin values
340
- # @see #perform
341
- def perform!(environment)
342
- self.children = perform_children(Environment.new(environment))
343
- end
344
-
345
- # Non-destructively runs \{#perform} on all children of the current node.
346
- #
347
- # @param environment [Sass::Environment] The lexical environment containing
348
- # variable and mixin values
349
- # @return [Array<Tree::Node>] The resulting static nodes
350
- def perform_children(environment)
351
- children.map {|c| c.perform(environment)}.flatten
352
- end
353
-
354
- # Replaces SassScript in a chunk of text
355
- # with the resulting value.
356
- #
357
- # @param text [Array<String, Sass::Script::Node>] The text to interpolate
358
- # @param environment [Sass::Environment] The lexical environment containing
359
- # variable and mixin values
360
- # @return [String] The interpolated text
361
- def run_interp(text, environment)
362
- text.map do |r|
363
- next r if r.is_a?(String)
364
- val = r.perform(environment)
365
- # Interpolated strings should never render with quotes
366
- next val.value if val.is_a?(Sass::Script::String)
367
- val.to_s
368
- end.join.strip
369
- end
370
-
371
- # @see Sass::Shared.balance
372
- # @raise [Sass::SyntaxError] if the brackets aren't balanced
373
- def balance(*args)
374
- res = Sass::Shared.balance(*args)
375
- return res if res
376
- raise Sass::SyntaxError.new("Unbalanced brackets.", :line => line)
377
- end
378
-
379
- # Returns an error message if the given child node is invalid,
380
- # and false otherwise.
381
- #
382
- # By default, all child nodes except those only allowed under specific nodes
383
- # ({Tree::MixinDefNode}, {Tree::ImportNode}, {Tree::ExtendNode}) are valid.
384
- # This is expected to be overriden by subclasses
385
- # for which some children are invalid.
386
- #
387
- # @param child [Tree::Node] A potential child node
388
- # @return [Boolean, String] Whether or not the child node is valid,
389
- # as well as the error message to display if it is invalid
390
- def invalid_child?(child)
391
- case child
392
- when Tree::MixinDefNode
393
- "Mixins may only be defined at the root of a document."
394
- when Tree::ImportNode
395
- "Import directives may only be used at the root of a document."
396
- when Tree::ExtendNode
397
- "Extend directives may only be used within rules."
398
- end
399
- end
400
-
401
- # Converts a node to Sass or SCSS code that will generate it.
402
- #
403
- # This method is called by the default \{#to\_sass} and \{#to\_scss} methods,
404
- # so that the same code can be used for both with minor variations.
405
- #
406
- # @param tabs [Fixnum] The amount of tabulation to use for the SCSS code
407
- # @param opts [{Symbol => Object}] An options hash (see {Sass::CSS#initialize})
408
- # @param fmt [Symbol] `:sass` or `:scss`
409
- # @return [String] The Sass or SCSS code corresponding to the node
410
- def to_src(tabs, opts, fmt)
411
- Sass::Util.abstract(self)
412
- end
413
-
414
- # Converts the children of this node to a Sass or SCSS string.
415
- # This will return the trailing newline for the previous line,
416
- # including brackets if this is SCSS.
417
- #
418
- # @param tabs [Fixnum] The amount of tabulation to use for the Sass code
419
- # @param opts [{Symbol => Object}] An options hash (see {Sass::CSS#initialize})
420
- # @param fmt [Symbol] `:sass` or `:scss`
421
- # @return [String] The Sass or SCSS code corresponding to the children
422
- def children_to_src(tabs, opts, fmt)
423
- return fmt == :sass ? "\n" : " {}\n" if children.empty?
424
-
425
- (fmt == :sass ? "\n" : " {\n") +
426
- children.map {|c| c.send("to_#{fmt}", tabs + 1, opts)}.join.rstrip +
427
- (fmt == :sass ? "\n" : " }\n")
428
- end
429
-
430
- # Converts a selector to a Sass or SCSS string.
431
- #
432
- # @param sel [Array<String, Sass::Script::Node>] The selector to convert
433
- # @param tabs [Fixnum] The indentation of the selector
434
- # @param opts [{Symbol => Object}] An options hash (see {Sass::CSS#initialize})
435
- # @param fmt [Symbol] `:sass` or `:scss`
436
- # @return [String] The Sass or SCSS code corresponding to the selector
437
- def selector_to_src(sel, tabs, opts, fmt)
438
- fmt == :sass ? selector_to_sass(sel, opts) : selector_to_scss(sel, tabs, opts)
439
- end
440
-
441
- # Converts a selector to a Sass string.
442
- #
443
- # @param sel [Array<String, Sass::Script::Node>] The selector to convert
444
- # @param opts [{Symbol => Object}] An options hash (see {Sass::CSS#initialize})
445
- # @return [String] The Sass code corresponding to the selector
446
- def selector_to_sass(sel, opts)
447
- sel.map do |r|
448
- if r.is_a?(String)
449
- r.gsub(/(,[ \t]*)?\n\s*/) {$1 ? $1 + "\n" : " "}
450
- else
451
- "\#{#{r.to_sass(opts)}}"
452
- end
453
- end.join
454
- end
455
-
456
- # Converts a selector to a SCSS string.
457
- #
458
- # @param sel [Array<String, Sass::Script::Node>] The selector to convert
459
- # @param tabs [Fixnum] The indentation of the selector
460
- # @param opts [{Symbol => Object}] An options hash (see {Sass::CSS#initialize})
461
- # @return [String] The SCSS code corresponding to the selector
462
- def selector_to_scss(sel, tabs, opts)
463
- sel.map {|r| r.is_a?(String) ? r : "\#{#{r.to_sass(opts)}}"}.
464
- join.gsub(/^[ \t]*/, ' ' * tabs)
465
- end
466
-
467
- # Convert any underscores in a string into hyphens,
468
- # but only if the `:dasherize` option is set.
469
- #
470
- # @param s [String] The string to convert
471
- # @param opts [{Symbol => Object}] The options hash
472
- # @return [String] The converted string
473
- def dasherize(s, opts)
474
- if opts[:dasherize]
475
- s.gsub('_', '-')
476
- else
477
- s
478
- end
479
- end
480
-
481
- # Returns a semicolon if this is SCSS, or an empty string if this is Sass.
482
- #
483
- # @param fmt [Symbol] `:sass` or `:scss`
484
- # @return [String] A semicolon or the empty string
485
- def semi(fmt)
486
- fmt == :sass ? "" : ";"
487
- end
488
- end
489
- end
490
- end