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,220 +0,0 @@
1
- module Sass::Tree
2
- # A static node reprenting a CSS property.
3
- #
4
- # @see Sass::Tree
5
- class PropNode < Node
6
- # The name of the property,
7
- # interspersed with {Sass::Script::Node}s
8
- # representing `#{}`-interpolation.
9
- # Any adjacent strings will be merged together.
10
- #
11
- # @return [Array<String, Sass::Script::Node>]
12
- attr_accessor :name
13
-
14
- # The name of the property
15
- # after any interpolated SassScript has been resolved.
16
- # Only set once \{Tree::Node#perform} has been called.
17
- #
18
- # @return [String]
19
- attr_accessor :resolved_name
20
-
21
- # The value of the property.
22
- #
23
- # @return [Sass::Script::Node]
24
- attr_accessor :value
25
-
26
- # The value of the property
27
- # after any interpolated SassScript has been resolved.
28
- # Only set once \{Tree::Node#perform} has been called.
29
- #
30
- # @return [String]
31
- attr_accessor :resolved_value
32
-
33
- # How deep this property is indented
34
- # relative to a normal property.
35
- # This is only greater than 0 in the case that:
36
- #
37
- # * This node is in a CSS tree
38
- # * The style is :nested
39
- # * This is a child property of another property
40
- # * The parent property has a value, and thus will be rendered
41
- #
42
- # @return [Fixnum]
43
- attr_accessor :tabs
44
-
45
- # @param name [Array<String, Sass::Script::Node>] See \{#name}
46
- # @param value [Sass::Script::Node] See \{#value}
47
- # @param prop_syntax [Symbol] `:new` if this property uses `a: b`-style syntax,
48
- # `:old` if it uses `:a b`-style syntax
49
- def initialize(name, value, prop_syntax)
50
- @name = Sass::Util.strip_string_array(
51
- Sass::Util.merge_adjacent_strings(name))
52
- @value = value
53
- @tabs = 0
54
- @prop_syntax = prop_syntax
55
- super()
56
- end
57
-
58
- # Compares the names and values of two properties.
59
- #
60
- # @param other [Object] The object to compare with
61
- # @return [Boolean] Whether or not this node and the other object
62
- # are the same
63
- def ==(other)
64
- self.class == other.class && name == other.name && value == other.value && super
65
- end
66
-
67
- # Returns a appropriate message indicating how to escape pseudo-class selectors.
68
- # This only applies for old-style properties with no value,
69
- # so returns the empty string if this is new-style.
70
- #
71
- # @return [String] The message
72
- def pseudo_class_selector_message
73
- return "" if @prop_syntax == :new || !value.is_a?(Sass::Script::String) || !value.value.empty?
74
- "\nIf #{declaration.dump} should be a selector, use \"\\#{declaration}\" instead."
75
- end
76
-
77
- protected
78
-
79
- # @see Node#to_src
80
- def to_src(tabs, opts, fmt)
81
- res = declaration(tabs, opts, fmt)
82
- return res + "#{semi fmt}\n" if children.empty?
83
- res + children_to_src(tabs, opts, fmt).rstrip + semi(fmt) + "\n"
84
- end
85
-
86
- # Computes the CSS for the property.
87
- #
88
- # @param tabs [Fixnum] The level of indentation for the CSS
89
- # @return [String] The resulting CSS
90
- def _to_s(tabs)
91
- to_return = ' ' * (tabs - 1 + self.tabs) + resolved_name + ":" +
92
- (style == :compressed ? '' : ' ') + resolved_value + (style == :compressed ? "" : ";")
93
- end
94
-
95
- # Converts nested properties into flat properties.
96
- #
97
- # @param extends [Sass::Util::SubsetMap{Selector::Simple => Selector::Sequence}]
98
- # The extensions defined for this tree
99
- # @param parent [PropNode, nil] The parent node of this node,
100
- # or nil if the parent isn't a {PropNode}
101
- # @raise [Sass::SyntaxError] if the property uses invalid syntax
102
- def _cssize(extends, parent)
103
- node = super
104
- result = node.children.dup
105
- if !node.resolved_value.empty? || node.children.empty?
106
- node.send(:check!)
107
- result.unshift(node)
108
- end
109
- result
110
- end
111
-
112
- # Updates the name and indentation of this node based on the parent name
113
- # and nesting level.
114
- #
115
- # @param extends [Sass::Util::SubsetMap{Selector::Simple => Selector::Sequence}]
116
- # The extensions defined for this tree
117
- # @param parent [PropNode, nil] The parent node of this node,
118
- # or nil if the parent isn't a {PropNode}
119
- def cssize!(extends, parent)
120
- self.resolved_name = "#{parent.resolved_name}-#{resolved_name}" if parent
121
- self.tabs = parent.tabs + (parent.resolved_value.empty? ? 0 : 1) if parent && style == :nested
122
- super
123
- end
124
-
125
- # Runs any SassScript that may be embedded in the property,
126
- # and invludes the parent property, if any.
127
- #
128
- # @param environment [Sass::Environment] The lexical environment containing
129
- # variable and mixin values
130
- def perform!(environment)
131
- @resolved_name = run_interp(@name, environment)
132
- val = @value.perform(environment)
133
- @resolved_value =
134
- if @value.context == :equals && val.is_a?(Sass::Script::String)
135
- val.value
136
- else
137
- val.to_s
138
- end
139
- super
140
- end
141
-
142
- # Returns an error message if the given child node is invalid,
143
- # and false otherwise.
144
- #
145
- # {PropNode} only allows other {PropNode}s and {CommentNode}s as children.
146
- # @param child [Tree::Node] A potential child node
147
- # @return [String] An error message if the child is invalid, or nil otherwise
148
- def invalid_child?(child)
149
- if !child.is_a?(PropNode) && !child.is_a?(CommentNode)
150
- "Illegal nesting: Only properties may be nested beneath properties."
151
- end
152
- end
153
-
154
- private
155
-
156
- def check!
157
- if @options[:property_syntax] == :old && @prop_syntax == :new
158
- raise Sass::SyntaxError.new("Illegal property syntax: can't use new syntax when :property_syntax => :old is set.")
159
- elsif @options[:property_syntax] == :new && @prop_syntax == :old
160
- raise Sass::SyntaxError.new("Illegal property syntax: can't use old syntax when :property_syntax => :new is set.")
161
- elsif resolved_value.empty?
162
- raise Sass::SyntaxError.new("Invalid property: #{declaration.dump} (no value)." +
163
- pseudo_class_selector_message)
164
- end
165
- end
166
-
167
- def declaration(tabs = 0, opts = {:old => @prop_syntax == :old}, fmt = :sass)
168
- name = self.name.map {|n| n.is_a?(String) ? n : "\#{#{n.to_sass(opts)}}"}.join
169
- if name[0] == ?:
170
- raise Sass::SyntaxError.new("The \"#{name}: #{self.class.val_to_sass(value, opts)}\" hack is not allowed in the Sass indented syntax")
171
- end
172
-
173
- old = opts[:old] && fmt == :sass
174
- initial = old ? ':' : ''
175
- mid = old ? '' : ':'
176
- "#{' ' * tabs}#{initial}#{name}#{mid} #{self.class.val_to_sass(value, opts)}".rstrip
177
- end
178
-
179
- class << self
180
- # @private
181
- def val_to_sass(value, opts)
182
- val_to_sass_comma(value, opts).to_sass(opts)
183
- end
184
-
185
- private
186
-
187
- def val_to_sass_comma(node, opts)
188
- return node unless node.is_a?(Sass::Script::Operation)
189
- return val_to_sass_concat(node, opts) unless node.operator == :comma
190
-
191
- Sass::Script::Operation.new(
192
- val_to_sass_concat(node.operand1, opts),
193
- val_to_sass_comma(node.operand2, opts),
194
- node.operator)
195
- end
196
-
197
- def val_to_sass_concat(node, opts)
198
- return node unless node.is_a?(Sass::Script::Operation)
199
- return val_to_sass_div(node, opts) unless node.operator == :concat
200
-
201
- Sass::Script::Operation.new(
202
- val_to_sass_div(node.operand1, opts),
203
- val_to_sass_concat(node.operand2, opts),
204
- node.operator)
205
- end
206
-
207
- def val_to_sass_div(node, opts)
208
- unless node.is_a?(Sass::Script::Operation) && node.operator == :div &&
209
- node.operand1.is_a?(Sass::Script::Number) &&
210
- node.operand2.is_a?(Sass::Script::Number) &&
211
- (node.context == :equals || !node.operand1.original || !node.operand2.original)
212
- return node
213
- end
214
-
215
- Sass::Script::String.new("(#{node.to_sass(opts)})")
216
- end
217
-
218
- end
219
- end
220
- end
@@ -1,125 +0,0 @@
1
- module Sass
2
- module Tree
3
- # A static node that is the root node of the Sass document.
4
- class RootNode < Node
5
- # The Sass template from which this node was created
6
- #
7
- # @param template [String]
8
- attr_reader :template
9
-
10
- # @param template [String] The Sass template from which this node was created
11
- def initialize(template)
12
- super()
13
- @template = template
14
- end
15
-
16
- # @see Node#to_s
17
- def to_s(*args)
18
- super
19
- rescue Sass::SyntaxError => e
20
- e.sass_template = @template
21
- raise e
22
- end
23
-
24
- # Runs the dynamic Sass code *and* computes the CSS for the tree.
25
- #
26
- # @see #perform
27
- # @see #to_s
28
- def render
29
- result, extends = perform(Environment.new).cssize
30
- result = result.do_extend(extends) unless extends.empty?
31
- result.to_s
32
- end
33
-
34
- # @see Node#perform
35
- def perform(environment)
36
- environment.options = @options if environment.options.nil? || environment.options.empty?
37
- super
38
- rescue Sass::SyntaxError => e
39
- e.sass_template = @template
40
- raise e
41
- end
42
-
43
- # Like {Node#cssize}, except that this method
44
- # will create its own `extends` map if necessary,
45
- # and it returns that map along with the cssized tree.
46
- #
47
- # @return [(Tree::Node, Sass::Util::SubsetMap)] The resulting tree of static nodes
48
- # *and* the extensions defined for this tree
49
- def cssize(extends = Sass::Util::SubsetMap.new, parent = nil)
50
- return super(extends), extends
51
- rescue Sass::SyntaxError => e
52
- e.sass_template = @template
53
- raise e
54
- end
55
-
56
- # @see \{Node#perform!}
57
- def perform!(environment)
58
- environment.options = @options if environment.options.nil? || environment.options.empty?
59
- super
60
- end
61
-
62
- # Converts a node to Sass code that will generate it.
63
- #
64
- # @param opts [{Symbol => Object}] An options hash (see {Sass::CSS#initialize})
65
- # @return [String] The Sass code corresponding to the node
66
- def to_sass(opts = {})
67
- to_src(opts, :sass)
68
- end
69
-
70
- # Converts a node to SCSS code that will generate it.
71
- #
72
- # @param opts [{Symbol => Object}] An options hash (see {Sass::CSS#initialize})
73
- # @return [String] The SCSS code corresponding to the node
74
- def to_scss(opts = {})
75
- to_src(opts, :scss)
76
- end
77
-
78
- protected
79
-
80
- # @see Node#to_src
81
- def to_src(opts, fmt)
82
- Sass::Util.enum_cons(children + [nil], 2).map do |child, nxt|
83
- child.send("to_#{fmt}", 0, opts) +
84
- if nxt &&
85
- (child.is_a?(CommentNode) && child.line + child.value.count("\n") + 1 == nxt.line) ||
86
- (child.is_a?(ImportNode) && nxt.is_a?(ImportNode) && child.line + 1 == nxt.line) ||
87
- (child.is_a?(VariableNode) && nxt.is_a?(VariableNode) && child.line + 1 == nxt.line)
88
- ""
89
- else
90
- "\n"
91
- end
92
- end.join.rstrip + "\n"
93
- end
94
-
95
- # Computes the CSS corresponding to this Sass tree.
96
- #
97
- # @param args [Array] ignored
98
- # @return [String] The resulting CSS
99
- # @see Sass::Tree
100
- def _to_s(*args)
101
- result = String.new
102
- children.each do |child|
103
- next if child.invisible?
104
- child_str = child.to_s(1)
105
- result << child_str + (style == :compressed ? '' : "\n")
106
- end
107
- result.rstrip!
108
- return "" if result.empty?
109
- return result + "\n"
110
- end
111
-
112
- # Returns an error message if the given child node is invalid,
113
- # and false otherwise.
114
- #
115
- # Only property nodes are invalid at root level.
116
- #
117
- # @see Node#invalid_child?
118
- def invalid_child?(child)
119
- return unless child.is_a?(Tree::PropNode)
120
- "Properties aren't allowed at the root of a document." +
121
- child.pseudo_class_selector_message
122
- end
123
- end
124
- end
125
- end
@@ -1,273 +0,0 @@
1
- require 'pathname'
2
- require 'uri'
3
-
4
- module Sass::Tree
5
- # A static node reprenting a CSS rule.
6
- #
7
- # @see Sass::Tree
8
- class RuleNode < Node
9
- # The character used to include the parent selector
10
- PARENT = '&'
11
-
12
- # The CSS selector for this rule,
13
- # interspersed with {Sass::Script::Node}s
14
- # representing `#{}`-interpolation.
15
- # Any adjacent strings will be merged together.
16
- #
17
- # @return [Array<String, Sass::Script::Node>]
18
- attr_accessor :rule
19
-
20
- # The CSS selector for this rule,
21
- # without any unresolved interpolation
22
- # but with parent references still intact.
23
- # It's only set once {Tree::Node#perform} has been called.
24
- #
25
- # @return [Selector::CommaSequence]
26
- attr_accessor :parsed_rules
27
-
28
- # The CSS selector for this rule,
29
- # without any unresolved interpolation or parent references.
30
- # It's only set once {Tree::Node#cssize} has been called.
31
- #
32
- # @return [Selector::CommaSequence]
33
- attr_accessor :resolved_rules
34
-
35
- # How deep this rule is indented
36
- # relative to a base-level rule.
37
- # This is only greater than 0 in the case that:
38
- #
39
- # * This node is in a CSS tree
40
- # * The style is :nested
41
- # * This is a child rule of another rule
42
- # * The parent rule has properties, and thus will be rendered
43
- #
44
- # @return [Fixnum]
45
- attr_accessor :tabs
46
-
47
- # Whether or not this rule is the last rule in a nested group.
48
- # This is only set in a CSS tree.
49
- #
50
- # @return [Boolean]
51
- attr_accessor :group_end
52
-
53
- # @param rule [Array<String, Sass::Script::Node>]
54
- # The CSS rule. See \{#rule}
55
- def initialize(rule)
56
- #p rule
57
- merged = Sass::Util.merge_adjacent_strings(rule)
58
- #p merged
59
- @rule = Sass::Util.strip_string_array(merged)
60
- #p @rule
61
- @tabs = 0
62
- super()
63
- end
64
-
65
- # Compares the contents of two rules.
66
- #
67
- # @param other [Object] The object to compare with
68
- # @return [Boolean] Whether or not this node and the other object
69
- # are the same
70
- def ==(other)
71
- self.class == other.class && rule == other.rule && super
72
- end
73
-
74
- # Adds another {RuleNode}'s rules to this one's.
75
- #
76
- # @param node [RuleNode] The other node
77
- def add_rules(node)
78
- @rule = Sass::Util.strip_string_array(
79
- Sass::Util.merge_adjacent_strings(@rule + ["\n"] + node.rule))
80
- end
81
-
82
- # @return [Boolean] Whether or not this rule is continued on the next line
83
- def continued?
84
- last = @rule.last
85
- last.is_a?(String) && last[-1] == ?,
86
- end
87
-
88
- # @see Node#to_sass
89
- def to_sass(tabs, opts = {})
90
- name = selector_to_sass(rule, opts)
91
- name = "\\" + name if name[0] == ?:
92
- name.gsub(/^/, ' ' * tabs) + children_to_src(tabs, opts, :sass)
93
- end
94
-
95
- # @see Node#to_scss
96
- def to_scss(tabs, opts = {})
97
- name = selector_to_scss(rule, tabs, opts)
98
- res = name + children_to_src(tabs, opts, :scss)
99
-
100
- if children.last.is_a?(CommentNode) && children.last.silent
101
- res.slice!(-3..-1)
102
- res << "\n" << (' ' * tabs) << "}\n"
103
- end
104
-
105
- res
106
- end
107
-
108
- # Extends this Rule's selector with the given `extends`.
109
- #
110
- # @see Node#do_extend
111
- def do_extend(extends)
112
- node = dup
113
- node.resolved_rules = resolved_rules.do_extend(extends)
114
- node
115
- end
116
-
117
- protected
118
-
119
- # Computes the CSS for the rule.
120
- #
121
- # @param tabs [Fixnum] The level of indentation for the CSS
122
- # @return [String] The resulting CSS
123
- def _to_s(tabs)
124
- tabs = tabs + self.tabs
125
-
126
- rule_separator = style == :compressed ? ',' : ', '
127
- line_separator =
128
- case style
129
- when :nested, :expanded; "\n"
130
- when :compressed; ""
131
- else; " "
132
- end
133
- rule_indent = ' ' * (tabs - 1)
134
- per_rule_indent, total_indent = [:nested, :expanded].include?(style) ? [rule_indent, ''] : ['', rule_indent]
135
-
136
- total_rule = total_indent + resolved_rules.members.
137
- map {|seq| seq.to_a.join.gsub(/([^,])\n/m, style == :compressed ? '\1 ' : "\\1\n")}.
138
- join(rule_separator).split("\n").map do |line|
139
- per_rule_indent + line.strip
140
- end.join(line_separator)
141
-
142
- to_return = ''
143
- old_spaces = ' ' * (tabs - 1)
144
- spaces = ' ' * tabs
145
- if style != :compressed
146
- if @options[:debug_info]
147
- to_return << debug_info_rule.to_s(tabs) << "\n"
148
- elsif @options[:line_comments]
149
- to_return << "#{old_spaces}/* line #{line}"
150
-
151
- if filename
152
- relative_filename = if @options[:css_filename]
153
- begin
154
- Pathname.new(filename).relative_path_from(
155
- Pathname.new(File.dirname(@options[:css_filename]))).to_s
156
- rescue ArgumentError
157
- nil
158
- end
159
- end
160
- relative_filename ||= filename
161
- to_return << ", #{relative_filename}"
162
- end
163
-
164
- to_return << " */\n"
165
- end
166
- end
167
-
168
- if style == :compact
169
- properties = children.map { |a| a.to_s(1) }.join(' ')
170
- to_return << "#{total_rule} { #{properties} }#{"\n" if group_end}"
171
- elsif style == :compressed
172
- properties = children.map { |a| a.to_s(1) }.join(';')
173
- to_return << "#{total_rule}{#{properties}}"
174
- else
175
- properties = children.map { |a| a.to_s(tabs + 1) }.join("\n")
176
- end_props = (style == :expanded ? "\n" + old_spaces : ' ')
177
- to_return << "#{total_rule} {\n#{properties}#{end_props}}#{"\n" if group_end}"
178
- end
179
-
180
- to_return
181
- end
182
-
183
- # Runs SassScript interpolation in the selector,
184
- # and then parses the result into a {Sass::Selector::CommaSequence}.
185
- #
186
- # @param environment [Sass::Environment] The lexical environment containing
187
- # variable and mixin values
188
- def perform!(environment)
189
- @parsed_rules = Sass::SCSS::StaticParser.new(run_interp(@rule, environment), self.line).
190
- parse_selector(self.filename)
191
- super
192
- end
193
-
194
- # Converts nested rules into a flat list of rules.
195
- #
196
- # @param extends [Sass::Util::SubsetMap{Selector::Simple => Selector::Sequence}]
197
- # The extensions defined for this tree
198
- # @param parent [RuleNode, nil] The parent node of this node,
199
- # or nil if the parent isn't a {RuleNode}
200
- def _cssize(extends, parent)
201
- node = super
202
- rules = node.children.select {|c| c.is_a?(RuleNode)}
203
- props = node.children.reject {|c| c.is_a?(RuleNode) || c.invisible?}
204
-
205
- unless props.empty?
206
- node.children = props
207
- rules.each {|r| r.tabs += 1} if style == :nested
208
- rules.unshift(node)
209
- end
210
-
211
- rules.last.group_end = true unless parent || rules.empty?
212
-
213
- rules
214
- end
215
-
216
- # Resolves parent references and nested selectors,
217
- # and updates the indentation based on the parent's indentation.
218
- #
219
- # @param extends [Sass::Util::SubsetMap{Selector::Simple => Selector::Sequence}]
220
- # The extensions defined for this tree
221
- # @param parent [RuleNode, nil] The parent node of this node,
222
- # or nil if the parent isn't a {RuleNode}
223
- # @raise [Sass::SyntaxError] if the rule has no parents but uses `&`
224
- def cssize!(extends, parent)
225
- self.resolved_rules = @parsed_rules.resolve_parent_refs(parent && parent.resolved_rules)
226
- super
227
- end
228
-
229
- # Returns an error message if the given child node is invalid,
230
- # and false otherwise.
231
- #
232
- # {ExtendNode}s are valid within {RuleNode}s.
233
- #
234
- # @param child [Tree::Node] A potential child node.
235
- # @return [Boolean, String] Whether or not the child node is valid,
236
- # as well as the error message to display if it is invalid
237
- def invalid_child?(child)
238
- super unless child.is_a?(ExtendNode)
239
- end
240
-
241
- # A hash that will be associated with this rule in the CSS document
242
- # if the {file:SASS_REFERENCE.md#debug_info-option `:debug_info` option} is enabled.
243
- # This data is used by e.g. [the FireSass Firebug extension](https://addons.mozilla.org/en-US/firefox/addon/103988).
244
- #
245
- # @return [{#to_s => #to_s}]
246
- def debug_info
247
- {:filename => filename && ("file://" + URI.escape(File.expand_path(filename))),
248
- :line => self.line}
249
- end
250
-
251
- private
252
-
253
- def debug_info_rule
254
- node = DirectiveNode.new("@media -sass-debug-info")
255
- debug_info.map {|k, v| [k.to_s, v.to_s]}.sort.each do |k, v|
256
- rule = RuleNode.new([""])
257
- rule.resolved_rules = Sass::Selector::CommaSequence.new(
258
- [Sass::Selector::Sequence.new(
259
- [Sass::Selector::SimpleSequence.new(
260
- [Sass::Selector::Element.new(k.to_s.gsub(/[^\w-]/, "\\\\\\0"), nil)])
261
- ])
262
- ])
263
- prop = PropNode.new([""], "", :new)
264
- prop.resolved_name = "font-family"
265
- prop.resolved_value = Sass::SCSS::RX.escape_ident(v.to_s)
266
- rule << prop
267
- node << rule
268
- end
269
- node.options = @options.merge(:debug_info => false, :line_comments => false, :style => :compressed)
270
- node
271
- end
272
- end
273
- end