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.
Files changed (268) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +11 -0
  3. data/CONTRIBUTING +3 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.md +221 -0
  6. data/Rakefile +370 -0
  7. data/VERSION +1 -0
  8. data/VERSION_NAME +1 -0
  9. data/bin/sass +13 -0
  10. data/bin/sass-convert +12 -0
  11. data/bin/scss +13 -0
  12. data/extra/update_watch.rb +13 -0
  13. data/init.rb +18 -0
  14. data/lib/sass/cache_stores/base.rb +88 -0
  15. data/lib/sass/cache_stores/chain.rb +34 -0
  16. data/lib/sass/cache_stores/filesystem.rb +60 -0
  17. data/lib/sass/cache_stores/memory.rb +47 -0
  18. data/lib/sass/cache_stores/null.rb +25 -0
  19. data/lib/sass/cache_stores.rb +15 -0
  20. data/lib/sass/callbacks.rb +67 -0
  21. data/lib/sass/css.rb +407 -0
  22. data/lib/sass/engine.rb +1181 -0
  23. data/lib/sass/environment.rb +191 -0
  24. data/lib/sass/error.rb +198 -0
  25. data/lib/sass/exec/base.rb +187 -0
  26. data/lib/sass/exec/sass_convert.rb +264 -0
  27. data/lib/sass/exec/sass_scss.rb +424 -0
  28. data/lib/sass/exec.rb +9 -0
  29. data/lib/sass/features.rb +47 -0
  30. data/lib/sass/importers/base.rb +182 -0
  31. data/lib/sass/importers/filesystem.rb +211 -0
  32. data/lib/sass/importers.rb +22 -0
  33. data/lib/sass/logger/base.rb +30 -0
  34. data/lib/sass/logger/log_level.rb +45 -0
  35. data/lib/sass/logger.rb +12 -0
  36. data/lib/sass/media.rb +210 -0
  37. data/lib/sass/plugin/compiler.rb +565 -0
  38. data/lib/sass/plugin/configuration.rb +118 -0
  39. data/lib/sass/plugin/generic.rb +15 -0
  40. data/lib/sass/plugin/merb.rb +48 -0
  41. data/lib/sass/plugin/rack.rb +60 -0
  42. data/lib/sass/plugin/rails.rb +47 -0
  43. data/lib/sass/plugin/staleness_checker.rb +199 -0
  44. data/lib/sass/plugin.rb +133 -0
  45. data/lib/sass/railtie.rb +10 -0
  46. data/lib/sass/repl.rb +57 -0
  47. data/lib/sass/root.rb +7 -0
  48. data/lib/sass/script/css_lexer.rb +33 -0
  49. data/lib/sass/script/css_parser.rb +34 -0
  50. data/lib/sass/script/functions.rb +2626 -0
  51. data/lib/sass/script/lexer.rb +449 -0
  52. data/lib/sass/script/parser.rb +637 -0
  53. data/lib/sass/script/tree/funcall.rb +306 -0
  54. data/lib/sass/script/tree/interpolation.rb +118 -0
  55. data/lib/sass/script/tree/list_literal.rb +77 -0
  56. data/lib/sass/script/tree/literal.rb +45 -0
  57. data/lib/sass/script/tree/map_literal.rb +64 -0
  58. data/lib/sass/script/tree/node.rb +109 -0
  59. data/lib/sass/script/tree/operation.rb +103 -0
  60. data/lib/sass/script/tree/selector.rb +26 -0
  61. data/lib/sass/script/tree/string_interpolation.rb +104 -0
  62. data/lib/sass/script/tree/unary_operation.rb +69 -0
  63. data/lib/sass/script/tree/variable.rb +57 -0
  64. data/lib/sass/script/tree.rb +16 -0
  65. data/lib/sass/script/value/arg_list.rb +36 -0
  66. data/lib/sass/script/value/base.rb +240 -0
  67. data/lib/sass/script/value/bool.rb +35 -0
  68. data/lib/sass/script/value/color.rb +680 -0
  69. data/lib/sass/script/value/helpers.rb +262 -0
  70. data/lib/sass/script/value/list.rb +113 -0
  71. data/lib/sass/script/value/map.rb +70 -0
  72. data/lib/sass/script/value/null.rb +44 -0
  73. data/lib/sass/script/value/number.rb +530 -0
  74. data/lib/sass/script/value/string.rb +97 -0
  75. data/lib/sass/script/value.rb +11 -0
  76. data/lib/sass/script.rb +66 -0
  77. data/lib/sass/scss/css_parser.rb +42 -0
  78. data/lib/sass/scss/parser.rb +1209 -0
  79. data/lib/sass/scss/rx.rb +141 -0
  80. data/lib/sass/scss/script_lexer.rb +15 -0
  81. data/lib/sass/scss/script_parser.rb +25 -0
  82. data/lib/sass/scss/static_parser.rb +368 -0
  83. data/lib/sass/scss.rb +16 -0
  84. data/lib/sass/selector/abstract_sequence.rb +109 -0
  85. data/lib/sass/selector/comma_sequence.rb +175 -0
  86. data/lib/sass/selector/pseudo.rb +256 -0
  87. data/lib/sass/selector/sequence.rb +600 -0
  88. data/lib/sass/selector/simple.rb +117 -0
  89. data/lib/sass/selector/simple_sequence.rb +325 -0
  90. data/lib/sass/selector.rb +326 -0
  91. data/lib/sass/shared.rb +76 -0
  92. data/lib/sass/source/map.rb +210 -0
  93. data/lib/sass/source/position.rb +39 -0
  94. data/lib/sass/source/range.rb +41 -0
  95. data/lib/sass/stack.rb +120 -0
  96. data/lib/sass/supports.rb +227 -0
  97. data/lib/sass/tree/at_root_node.rb +83 -0
  98. data/lib/sass/tree/charset_node.rb +22 -0
  99. data/lib/sass/tree/comment_node.rb +82 -0
  100. data/lib/sass/tree/content_node.rb +9 -0
  101. data/lib/sass/tree/css_import_node.rb +60 -0
  102. data/lib/sass/tree/debug_node.rb +18 -0
  103. data/lib/sass/tree/directive_node.rb +59 -0
  104. data/lib/sass/tree/each_node.rb +24 -0
  105. data/lib/sass/tree/error_node.rb +18 -0
  106. data/lib/sass/tree/extend_node.rb +43 -0
  107. data/lib/sass/tree/for_node.rb +36 -0
  108. data/lib/sass/tree/function_node.rb +39 -0
  109. data/lib/sass/tree/if_node.rb +52 -0
  110. data/lib/sass/tree/import_node.rb +74 -0
  111. data/lib/sass/tree/keyframe_rule_node.rb +15 -0
  112. data/lib/sass/tree/media_node.rb +48 -0
  113. data/lib/sass/tree/mixin_def_node.rb +38 -0
  114. data/lib/sass/tree/mixin_node.rb +52 -0
  115. data/lib/sass/tree/node.rb +238 -0
  116. data/lib/sass/tree/prop_node.rb +171 -0
  117. data/lib/sass/tree/return_node.rb +19 -0
  118. data/lib/sass/tree/root_node.rb +44 -0
  119. data/lib/sass/tree/rule_node.rb +145 -0
  120. data/lib/sass/tree/supports_node.rb +38 -0
  121. data/lib/sass/tree/trace_node.rb +33 -0
  122. data/lib/sass/tree/variable_node.rb +36 -0
  123. data/lib/sass/tree/visitors/base.rb +72 -0
  124. data/lib/sass/tree/visitors/check_nesting.rb +177 -0
  125. data/lib/sass/tree/visitors/convert.rb +334 -0
  126. data/lib/sass/tree/visitors/cssize.rb +369 -0
  127. data/lib/sass/tree/visitors/deep_copy.rb +107 -0
  128. data/lib/sass/tree/visitors/extend.rb +68 -0
  129. data/lib/sass/tree/visitors/perform.rb +539 -0
  130. data/lib/sass/tree/visitors/set_options.rb +139 -0
  131. data/lib/sass/tree/visitors/to_css.rb +381 -0
  132. data/lib/sass/tree/warn_node.rb +18 -0
  133. data/lib/sass/tree/while_node.rb +18 -0
  134. data/lib/sass/util/cross_platform_random.rb +19 -0
  135. data/lib/sass/util/multibyte_string_scanner.rb +157 -0
  136. data/lib/sass/util/normalized_map.rb +130 -0
  137. data/lib/sass/util/ordered_hash.rb +192 -0
  138. data/lib/sass/util/subset_map.rb +110 -0
  139. data/lib/sass/util/test.rb +9 -0
  140. data/lib/sass/util.rb +1318 -0
  141. data/lib/sass/version.rb +124 -0
  142. data/lib/sass.rb +102 -0
  143. data/rails/init.rb +1 -0
  144. data/test/sass/cache_test.rb +131 -0
  145. data/test/sass/callbacks_test.rb +61 -0
  146. data/test/sass/compiler_test.rb +232 -0
  147. data/test/sass/conversion_test.rb +2054 -0
  148. data/test/sass/css2sass_test.rb +477 -0
  149. data/test/sass/data/hsl-rgb.txt +319 -0
  150. data/test/sass/encoding_test.rb +219 -0
  151. data/test/sass/engine_test.rb +3301 -0
  152. data/test/sass/exec_test.rb +86 -0
  153. data/test/sass/extend_test.rb +1661 -0
  154. data/test/sass/fixtures/test_staleness_check_across_importers.css +1 -0
  155. data/test/sass/fixtures/test_staleness_check_across_importers.scss +1 -0
  156. data/test/sass/functions_test.rb +1926 -0
  157. data/test/sass/importer_test.rb +412 -0
  158. data/test/sass/logger_test.rb +58 -0
  159. data/test/sass/mock_importer.rb +49 -0
  160. data/test/sass/more_results/more1.css +9 -0
  161. data/test/sass/more_results/more1_with_line_comments.css +26 -0
  162. data/test/sass/more_results/more_import.css +29 -0
  163. data/test/sass/more_templates/_more_partial.sass +2 -0
  164. data/test/sass/more_templates/more1.sass +23 -0
  165. data/test/sass/more_templates/more_import.sass +11 -0
  166. data/test/sass/plugin_test.rb +554 -0
  167. data/test/sass/results/alt.css +4 -0
  168. data/test/sass/results/basic.css +9 -0
  169. data/test/sass/results/cached_import_option.css +3 -0
  170. data/test/sass/results/compact.css +5 -0
  171. data/test/sass/results/complex.css +86 -0
  172. data/test/sass/results/compressed.css +1 -0
  173. data/test/sass/results/expanded.css +19 -0
  174. data/test/sass/results/filename_fn.css +3 -0
  175. data/test/sass/results/if.css +3 -0
  176. data/test/sass/results/import.css +31 -0
  177. data/test/sass/results/import_charset.css +5 -0
  178. data/test/sass/results/import_charset_1_8.css +5 -0
  179. data/test/sass/results/import_charset_ibm866.css +5 -0
  180. data/test/sass/results/import_content.css +1 -0
  181. data/test/sass/results/line_numbers.css +49 -0
  182. data/test/sass/results/mixins.css +95 -0
  183. data/test/sass/results/multiline.css +24 -0
  184. data/test/sass/results/nested.css +22 -0
  185. data/test/sass/results/options.css +1 -0
  186. data/test/sass/results/parent_ref.css +13 -0
  187. data/test/sass/results/script.css +16 -0
  188. data/test/sass/results/scss_import.css +31 -0
  189. data/test/sass/results/scss_importee.css +2 -0
  190. data/test/sass/results/subdir/nested_subdir/nested_subdir.css +1 -0
  191. data/test/sass/results/subdir/subdir.css +3 -0
  192. data/test/sass/results/units.css +11 -0
  193. data/test/sass/results/warn.css +0 -0
  194. data/test/sass/results/warn_imported.css +0 -0
  195. data/test/sass/script_conversion_test.rb +328 -0
  196. data/test/sass/script_test.rb +1054 -0
  197. data/test/sass/scss/css_test.rb +1215 -0
  198. data/test/sass/scss/rx_test.rb +156 -0
  199. data/test/sass/scss/scss_test.rb +3900 -0
  200. data/test/sass/scss/test_helper.rb +37 -0
  201. data/test/sass/source_map_test.rb +977 -0
  202. data/test/sass/superselector_test.rb +191 -0
  203. data/test/sass/templates/_cached_import_option_partial.scss +1 -0
  204. data/test/sass/templates/_double_import_loop2.sass +1 -0
  205. data/test/sass/templates/_filename_fn_import.scss +11 -0
  206. data/test/sass/templates/_imported_charset_ibm866.sass +4 -0
  207. data/test/sass/templates/_imported_charset_utf8.sass +4 -0
  208. data/test/sass/templates/_imported_content.sass +3 -0
  209. data/test/sass/templates/_partial.sass +2 -0
  210. data/test/sass/templates/_same_name_different_partiality.scss +1 -0
  211. data/test/sass/templates/alt.sass +16 -0
  212. data/test/sass/templates/basic.sass +23 -0
  213. data/test/sass/templates/bork1.sass +2 -0
  214. data/test/sass/templates/bork2.sass +2 -0
  215. data/test/sass/templates/bork3.sass +2 -0
  216. data/test/sass/templates/bork4.sass +2 -0
  217. data/test/sass/templates/bork5.sass +3 -0
  218. data/test/sass/templates/cached_import_option.scss +3 -0
  219. data/test/sass/templates/compact.sass +17 -0
  220. data/test/sass/templates/complex.sass +305 -0
  221. data/test/sass/templates/compressed.sass +15 -0
  222. data/test/sass/templates/double_import_loop1.sass +1 -0
  223. data/test/sass/templates/expanded.sass +17 -0
  224. data/test/sass/templates/filename_fn.scss +18 -0
  225. data/test/sass/templates/if.sass +11 -0
  226. data/test/sass/templates/import.sass +12 -0
  227. data/test/sass/templates/import_charset.sass +9 -0
  228. data/test/sass/templates/import_charset_1_8.sass +6 -0
  229. data/test/sass/templates/import_charset_ibm866.sass +11 -0
  230. data/test/sass/templates/import_content.sass +4 -0
  231. data/test/sass/templates/importee.less +2 -0
  232. data/test/sass/templates/importee.sass +19 -0
  233. data/test/sass/templates/line_numbers.sass +13 -0
  234. data/test/sass/templates/mixin_bork.sass +5 -0
  235. data/test/sass/templates/mixins.sass +76 -0
  236. data/test/sass/templates/multiline.sass +20 -0
  237. data/test/sass/templates/nested.sass +25 -0
  238. data/test/sass/templates/nested_bork1.sass +2 -0
  239. data/test/sass/templates/nested_bork2.sass +2 -0
  240. data/test/sass/templates/nested_bork3.sass +2 -0
  241. data/test/sass/templates/nested_bork4.sass +2 -0
  242. data/test/sass/templates/nested_import.sass +2 -0
  243. data/test/sass/templates/nested_mixin_bork.sass +6 -0
  244. data/test/sass/templates/options.sass +2 -0
  245. data/test/sass/templates/parent_ref.sass +25 -0
  246. data/test/sass/templates/same_name_different_ext.sass +2 -0
  247. data/test/sass/templates/same_name_different_ext.scss +1 -0
  248. data/test/sass/templates/same_name_different_partiality.scss +1 -0
  249. data/test/sass/templates/script.sass +101 -0
  250. data/test/sass/templates/scss_import.scss +12 -0
  251. data/test/sass/templates/scss_importee.scss +1 -0
  252. data/test/sass/templates/single_import_loop.sass +1 -0
  253. data/test/sass/templates/subdir/import_up1.scss +1 -0
  254. data/test/sass/templates/subdir/import_up2.scss +1 -0
  255. data/test/sass/templates/subdir/nested_subdir/_nested_partial.sass +2 -0
  256. data/test/sass/templates/subdir/nested_subdir/nested_subdir.sass +3 -0
  257. data/test/sass/templates/subdir/subdir.sass +6 -0
  258. data/test/sass/templates/units.sass +11 -0
  259. data/test/sass/templates/warn.sass +3 -0
  260. data/test/sass/templates/warn_imported.sass +4 -0
  261. data/test/sass/test_helper.rb +8 -0
  262. data/test/sass/util/multibyte_string_scanner_test.rb +147 -0
  263. data/test/sass/util/normalized_map_test.rb +51 -0
  264. data/test/sass/util/subset_map_test.rb +91 -0
  265. data/test/sass/util_test.rb +467 -0
  266. data/test/sass/value_helpers_test.rb +179 -0
  267. data/test/test_helper.rb +109 -0
  268. metadata +386 -0
@@ -0,0 +1,52 @@
1
+ require 'sass/tree/node'
2
+
3
+ module Sass::Tree
4
+ # A static node representing a mixin include.
5
+ # When in a static tree, the sole purpose is to wrap exceptions
6
+ # to add the mixin to the backtrace.
7
+ #
8
+ # @see Sass::Tree
9
+ class MixinNode < Node
10
+ # The name of the mixin.
11
+ # @return [String]
12
+ attr_reader :name
13
+
14
+ # The arguments to the mixin.
15
+ # @return [Array<Script::Tree::Node>]
16
+ attr_accessor :args
17
+
18
+ # A hash from keyword argument names to values.
19
+ # @return [Sass::Util::NormalizedMap<Script::Tree::Node>]
20
+ attr_accessor :keywords
21
+
22
+ # The first splat argument for this mixin, if one exists.
23
+ #
24
+ # This could be a list of positional arguments, a map of keyword
25
+ # arguments, or an arglist containing both.
26
+ #
27
+ # @return [Node?]
28
+ attr_accessor :splat
29
+
30
+ # The second splat argument for this mixin, if one exists.
31
+ #
32
+ # If this exists, it's always a map of keyword arguments, and
33
+ # \{#splat} is always either a list or an arglist.
34
+ #
35
+ # @return [Node?]
36
+ attr_accessor :kwarg_splat
37
+
38
+ # @param name [String] The name of the mixin
39
+ # @param args [Array<Script::Tree::Node>] See \{#args}
40
+ # @param splat [Script::Tree::Node] See \{#splat}
41
+ # @param kwarg_splat [Script::Tree::Node] See \{#kwarg_splat}
42
+ # @param keywords [Sass::Util::NormalizedMap<Script::Tree::Node>] See \{#keywords}
43
+ def initialize(name, args, keywords, splat, kwarg_splat)
44
+ @name = name
45
+ @args = args
46
+ @keywords = keywords
47
+ @splat = splat
48
+ @kwarg_splat = kwarg_splat
49
+ super()
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,238 @@
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::Visitors::Perform} creates a static Sass tree, which is
12
+ # different. It still has nodes for CSS rules and properties but it
13
+ # doesn't have any dynamic-generation-related nodes. The nodes in
14
+ # this state are in a similar structure to the Sass document: rules
15
+ # and properties are nested beneath one another, although the
16
+ # {Tree::RuleNode} selectors are already in their final state. Nodes
17
+ # that can be in this state or in the dynamic state are called
18
+ # **static nodes**; nodes that can only be in this state are called
19
+ # **solely static nodes**.
20
+ #
21
+ # {Tree::Visitors::Cssize} is then used to create a static CSS tree.
22
+ # This is like a static Sass tree,
23
+ # but the structure exactly mirrors that of the generated CSS.
24
+ # Rules and properties can't be nested beneath one another in this state.
25
+ #
26
+ # Finally, {Tree::Visitors::ToCss} can be called on a static CSS tree
27
+ # to get the actual CSS code as a string.
28
+ module Tree
29
+ # The abstract superclass of all parse-tree nodes.
30
+ class Node
31
+ include Enumerable
32
+
33
+ def self.inherited(base)
34
+ node_name = base.name.gsub(/.*::(.*?)Node$/, '\\1').downcase
35
+ base.instance_eval <<-METHODS
36
+ # @return [Symbol] The name that is used for this node when visiting.
37
+ def node_name
38
+ :#{node_name}
39
+ end
40
+
41
+ # @return [Symbol] The method that is used on the visitor to visit nodes of this type.
42
+ def visit_method
43
+ :visit_#{node_name}
44
+ end
45
+
46
+ # @return [Symbol] The method name that determines if the parent is invalid.
47
+ def invalid_child_method_name
48
+ :"invalid_#{node_name}_child?"
49
+ end
50
+
51
+ # @return [Symbol] The method name that determines if the node is an invalid parent.
52
+ def invalid_parent_method_name
53
+ :"invalid_#{node_name}_parent?"
54
+ end
55
+ METHODS
56
+ end
57
+
58
+ # The child nodes of this node.
59
+ #
60
+ # @return [Array<Tree::Node>]
61
+ attr_reader :children
62
+
63
+ # Whether or not this node has child nodes.
64
+ # This may be true even when \{#children} is empty,
65
+ # in which case this node has an empty block (e.g. `{}`).
66
+ #
67
+ # @return [Boolean]
68
+ attr_accessor :has_children
69
+
70
+ # The line of the document on which this node appeared.
71
+ #
72
+ # @return [Fixnum]
73
+ attr_accessor :line
74
+
75
+ # The source range in the document on which this node appeared.
76
+ #
77
+ # @return [Sass::Source::Range]
78
+ attr_accessor :source_range
79
+
80
+ # The name of the document on which this node appeared.
81
+ #
82
+ # @return [String]
83
+ attr_writer :filename
84
+
85
+ # The options hash for the node.
86
+ # See {file:SASS_REFERENCE.md#sass_options the Sass options documentation}.
87
+ #
88
+ # @return [{Symbol => Object}]
89
+ attr_reader :options
90
+
91
+ def initialize
92
+ @children = []
93
+ end
94
+
95
+ # Sets the options hash for the node and all its children.
96
+ #
97
+ # @param options [{Symbol => Object}] The options
98
+ # @see #options
99
+ def options=(options)
100
+ Sass::Tree::Visitors::SetOptions.visit(self, options)
101
+ end
102
+
103
+ # @private
104
+ def children=(children)
105
+ self.has_children ||= !children.empty?
106
+ @children = children
107
+ end
108
+
109
+ # The name of the document on which this node appeared.
110
+ #
111
+ # @return [String]
112
+ def filename
113
+ @filename || (@options && @options[:filename])
114
+ end
115
+
116
+ # Appends a child to the node.
117
+ #
118
+ # @param child [Tree::Node, Array<Tree::Node>] The child node or nodes
119
+ # @raise [Sass::SyntaxError] if `child` is invalid
120
+ def <<(child)
121
+ return if child.nil?
122
+ if child.is_a?(Array)
123
+ child.each {|c| self << c}
124
+ else
125
+ self.has_children = true
126
+ @children << child
127
+ end
128
+ end
129
+
130
+ # Compares this node and another object (only other {Tree::Node}s will be equal).
131
+ # This does a structural comparison;
132
+ # if the contents of the nodes and all the child nodes are equivalent,
133
+ # then the nodes are as well.
134
+ #
135
+ # Only static nodes need to override this.
136
+ #
137
+ # @param other [Object] The object to compare with
138
+ # @return [Boolean] Whether or not this node and the other object
139
+ # are the same
140
+ # @see Sass::Tree
141
+ def ==(other)
142
+ self.class == other.class && other.children == children
143
+ end
144
+
145
+ # True if \{#to\_s} will return `nil`;
146
+ # that is, if the node shouldn't be rendered.
147
+ # Should only be called in a static tree.
148
+ #
149
+ # @return [Boolean]
150
+ def invisible?; false; end
151
+
152
+ # The output style. See {file:SASS_REFERENCE.md#sass_options the Sass options documentation}.
153
+ #
154
+ # @return [Symbol]
155
+ def style
156
+ @options[:style]
157
+ end
158
+
159
+ # Computes the CSS corresponding to this static CSS tree.
160
+ #
161
+ # @return [String] The resulting CSS
162
+ # @see Sass::Tree
163
+ def css
164
+ Sass::Tree::Visitors::ToCss.new.visit(self)
165
+ end
166
+
167
+ # Computes the CSS corresponding to this static CSS tree, along with
168
+ # the respective source map.
169
+ #
170
+ # @return [(String, Sass::Source::Map)] The resulting CSS and the source map
171
+ # @see Sass::Tree
172
+ def css_with_sourcemap
173
+ visitor = Sass::Tree::Visitors::ToCss.new(:build_source_mapping)
174
+ result = visitor.visit(self)
175
+ return result, visitor.source_mapping
176
+ end
177
+
178
+ # Returns a representation of the node for debugging purposes.
179
+ #
180
+ # @return [String]
181
+ def inspect
182
+ return self.class.to_s unless has_children
183
+ "(#{self.class} #{children.map {|c| c.inspect}.join(' ')})"
184
+ end
185
+
186
+ # Iterates through each node in the tree rooted at this node
187
+ # in a pre-order walk.
188
+ #
189
+ # @yield node
190
+ # @yieldparam node [Node] a node in the tree
191
+ def each
192
+ yield self
193
+ children.each {|c| c.each {|n| yield n}}
194
+ end
195
+
196
+ # Converts a node to Sass code that will generate it.
197
+ #
198
+ # @param options [{Symbol => Object}] An options hash (see {Sass::CSS#initialize})
199
+ # @return [String] The Sass code corresponding to the node
200
+ def to_sass(options = {})
201
+ Sass::Tree::Visitors::Convert.visit(self, options, :sass)
202
+ end
203
+
204
+ # Converts a node to SCSS code that will generate it.
205
+ #
206
+ # @param options [{Symbol => Object}] An options hash (see {Sass::CSS#initialize})
207
+ # @return [String] The Sass code corresponding to the node
208
+ def to_scss(options = {})
209
+ Sass::Tree::Visitors::Convert.visit(self, options, :scss)
210
+ end
211
+
212
+ # Return a deep clone of this node.
213
+ # The child nodes are cloned, but options are not.
214
+ #
215
+ # @return [Node]
216
+ def deep_copy
217
+ Sass::Tree::Visitors::DeepCopy.visit(self)
218
+ end
219
+
220
+ # Whether or not this node bubbles up through RuleNodes.
221
+ #
222
+ # @return [Boolean]
223
+ def bubbles?
224
+ false
225
+ end
226
+
227
+ protected
228
+
229
+ # @see Sass::Shared.balance
230
+ # @raise [Sass::SyntaxError] if the brackets aren't balanced
231
+ def balance(*args)
232
+ res = Sass::Shared.balance(*args)
233
+ return res if res
234
+ raise Sass::SyntaxError.new("Unbalanced brackets.", :line => line)
235
+ end
236
+ end
237
+ end
238
+ end
@@ -0,0 +1,171 @@
1
+ module Sass::Tree
2
+ # A static node representing a CSS property.
3
+ #
4
+ # @see Sass::Tree
5
+ class PropNode < Node
6
+ # The name of the property,
7
+ # interspersed with {Sass::Script::Tree::Node}s
8
+ # representing `#{}`-interpolation.
9
+ # Any adjacent strings will be merged together.
10
+ #
11
+ # @return [Array<String, Sass::Script::Tree::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::Visitors::Perform} has been run.
17
+ #
18
+ # @return [String]
19
+ attr_accessor :resolved_name
20
+
21
+ # The value of the property.
22
+ #
23
+ # @return [Sass::Script::Tree::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::Visitors::Perform} has been run.
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
+ # The source range in which the property name appears.
46
+ #
47
+ # @return [Sass::Source::Range]
48
+ attr_accessor :name_source_range
49
+
50
+ # The source range in which the property value appears.
51
+ #
52
+ # @return [Sass::Source::Range]
53
+ attr_accessor :value_source_range
54
+
55
+ # @param name [Array<String, Sass::Script::Tree::Node>] See \{#name}
56
+ # @param value [Sass::Script::Tree::Node] See \{#value}
57
+ # @param prop_syntax [Symbol] `:new` if this property uses `a: b`-style syntax,
58
+ # `:old` if it uses `:a b`-style syntax
59
+ def initialize(name, value, prop_syntax)
60
+ @name = Sass::Util.strip_string_array(
61
+ Sass::Util.merge_adjacent_strings(name))
62
+ @value = value
63
+ @tabs = 0
64
+ @prop_syntax = prop_syntax
65
+ super()
66
+ end
67
+
68
+ # Compares the names and values of two properties.
69
+ #
70
+ # @param other [Object] The object to compare with
71
+ # @return [Boolean] Whether or not this node and the other object
72
+ # are the same
73
+ def ==(other)
74
+ self.class == other.class && name == other.name && value == other.value && super
75
+ end
76
+
77
+ # Returns a appropriate message indicating how to escape pseudo-class selectors.
78
+ # This only applies for old-style properties with no value,
79
+ # so returns the empty string if this is new-style.
80
+ #
81
+ # @return [String] The message
82
+ def pseudo_class_selector_message
83
+ if @prop_syntax == :new ||
84
+ !value.is_a?(Sass::Script::Tree::Literal) ||
85
+ !value.value.is_a?(Sass::Script::Value::String) ||
86
+ !value.value.value.empty?
87
+ return ""
88
+ end
89
+
90
+ "\nIf #{declaration.dump} should be a selector, use \"\\#{declaration}\" instead."
91
+ end
92
+
93
+ # Computes the Sass or SCSS code for the variable declaration.
94
+ # This is like \{#to\_scss} or \{#to\_sass},
95
+ # except it doesn't print any child properties or a trailing semicolon.
96
+ #
97
+ # @param opts [{Symbol => Object}] The options hash for the tree.
98
+ # @param fmt [Symbol] `:scss` or `:sass`.
99
+ def declaration(opts = {:old => @prop_syntax == :old}, fmt = :sass)
100
+ name = self.name.map {|n| n.is_a?(String) ? n : n.to_sass(opts)}.join
101
+ if name[0] == ?:
102
+ raise Sass::SyntaxError.new("The \"#{name}: #{self.class.val_to_sass(value, opts)}\"" +
103
+ " hack is not allowed in the Sass indented syntax")
104
+ end
105
+
106
+ old = opts[:old] && fmt == :sass
107
+ initial = old ? ':' : ''
108
+ mid = old ? '' : ':'
109
+ "#{initial}#{name}#{mid} #{self.class.val_to_sass(value, opts)}".rstrip
110
+ end
111
+
112
+ # A property node is invisible if its value is empty.
113
+ #
114
+ # @return [Boolean]
115
+ def invisible?
116
+ resolved_value.empty?
117
+ end
118
+
119
+ private
120
+
121
+ def check!
122
+ if @options[:property_syntax] && @options[:property_syntax] != @prop_syntax
123
+ raise Sass::SyntaxError.new(
124
+ "Illegal property syntax: can't use #{@prop_syntax} syntax when " +
125
+ ":property_syntax => #{@options[:property_syntax].inspect} is set.")
126
+ end
127
+ end
128
+
129
+ class << self
130
+ # @private
131
+ def val_to_sass(value, opts)
132
+ val_to_sass_comma(value, opts).to_sass(opts)
133
+ end
134
+
135
+ private
136
+
137
+ def val_to_sass_comma(node, opts)
138
+ return node unless node.is_a?(Sass::Script::Tree::Operation)
139
+ return val_to_sass_concat(node, opts) unless node.operator == :comma
140
+
141
+ Sass::Script::Tree::Operation.new(
142
+ val_to_sass_concat(node.operand1, opts),
143
+ val_to_sass_comma(node.operand2, opts),
144
+ node.operator)
145
+ end
146
+
147
+ def val_to_sass_concat(node, opts)
148
+ return node unless node.is_a?(Sass::Script::Tree::Operation)
149
+ return val_to_sass_div(node, opts) unless node.operator == :space
150
+
151
+ Sass::Script::Tree::Operation.new(
152
+ val_to_sass_div(node.operand1, opts),
153
+ val_to_sass_concat(node.operand2, opts),
154
+ node.operator)
155
+ end
156
+
157
+ def val_to_sass_div(node, opts)
158
+ unless node.is_a?(Sass::Script::Tree::Operation) && node.operator == :div &&
159
+ node.operand1.is_a?(Sass::Script::Tree::Literal) &&
160
+ node.operand1.value.is_a?(Sass::Script::Value::Number) &&
161
+ node.operand2.is_a?(Sass::Script::Tree::Literal) &&
162
+ node.operand2.value.is_a?(Sass::Script::Value::Number) &&
163
+ (!node.operand1.value.original || !node.operand2.value.original)
164
+ return node
165
+ end
166
+
167
+ Sass::Script::Value::String.new("(#{node.to_sass(opts)})")
168
+ end
169
+ end
170
+ end
171
+ end