haml 3.1.0 → 3.1.1

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 (87) hide show
  1. data/VERSION +1 -1
  2. data/vendor/sass/Rakefile +22 -46
  3. data/vendor/sass/VERSION +1 -1
  4. data/vendor/sass/VERSION_NAME +1 -1
  5. data/vendor/sass/bin/scss +8 -0
  6. data/vendor/sass/doc-src/SASS_CHANGELOG.md +125 -9
  7. data/vendor/sass/doc-src/SASS_REFERENCE.md +84 -8
  8. data/vendor/sass/lib/sass.rb +0 -3
  9. data/vendor/sass/lib/sass/cache_stores.rb +1 -0
  10. data/vendor/sass/lib/sass/cache_stores/base.rb +2 -2
  11. data/vendor/sass/lib/sass/cache_stores/chain.rb +33 -0
  12. data/vendor/sass/lib/sass/cache_stores/filesystem.rb +6 -4
  13. data/vendor/sass/lib/sass/cache_stores/memory.rb +8 -12
  14. data/vendor/sass/lib/sass/engine.rb +65 -56
  15. data/vendor/sass/lib/sass/environment.rb +5 -2
  16. data/vendor/sass/lib/sass/exec.rb +52 -21
  17. data/vendor/sass/lib/sass/importers/filesystem.rb +32 -9
  18. data/vendor/sass/lib/sass/less.rb +1 -1
  19. data/vendor/sass/lib/sass/plugin.rb +11 -1
  20. data/vendor/sass/lib/sass/plugin/compiler.rb +21 -12
  21. data/vendor/sass/lib/sass/plugin/rails.rb +8 -82
  22. data/vendor/sass/lib/sass/plugin/staleness_checker.rb +10 -10
  23. data/vendor/sass/lib/sass/railtie.rb +3 -2
  24. data/vendor/sass/lib/sass/script.rb +2 -25
  25. data/vendor/sass/lib/sass/script/color.rb +4 -15
  26. data/vendor/sass/lib/sass/script/funcall.rb +63 -19
  27. data/vendor/sass/lib/sass/script/functions.rb +257 -19
  28. data/vendor/sass/lib/sass/script/lexer.rb +1 -4
  29. data/vendor/sass/lib/sass/script/list.rb +2 -2
  30. data/vendor/sass/lib/sass/script/node.rb +0 -27
  31. data/vendor/sass/lib/sass/script/number.rb +1 -1
  32. data/vendor/sass/lib/sass/script/operation.rb +0 -5
  33. data/vendor/sass/lib/sass/script/parser.rb +30 -12
  34. data/vendor/sass/lib/sass/script/string.rb +2 -17
  35. data/vendor/sass/lib/sass/script/string_interpolation.rb +1 -0
  36. data/vendor/sass/lib/sass/scss/parser.rb +58 -18
  37. data/vendor/sass/lib/sass/scss/rx.rb +2 -1
  38. data/vendor/sass/lib/sass/scss/script_lexer.rb +1 -1
  39. data/vendor/sass/lib/sass/selector/comma_sequence.rb +2 -3
  40. data/vendor/sass/lib/sass/selector/sequence.rb +3 -6
  41. data/vendor/sass/lib/sass/selector/simple_sequence.rb +2 -3
  42. data/vendor/sass/lib/sass/tree/charset_node.rb +0 -15
  43. data/vendor/sass/lib/sass/tree/comment_node.rb +20 -71
  44. data/vendor/sass/lib/sass/tree/debug_node.rb +4 -22
  45. data/vendor/sass/lib/sass/tree/directive_node.rb +0 -52
  46. data/vendor/sass/lib/sass/tree/each_node.rb +8 -38
  47. data/vendor/sass/lib/sass/tree/extend_node.rb +12 -48
  48. data/vendor/sass/lib/sass/tree/for_node.rb +20 -51
  49. data/vendor/sass/lib/sass/tree/function_node.rb +27 -0
  50. data/vendor/sass/lib/sass/tree/if_node.rb +22 -57
  51. data/vendor/sass/lib/sass/tree/import_node.rb +0 -56
  52. data/vendor/sass/lib/sass/tree/media_node.rb +0 -43
  53. data/vendor/sass/lib/sass/tree/mixin_def_node.rb +12 -45
  54. data/vendor/sass/lib/sass/tree/mixin_node.rb +13 -124
  55. data/vendor/sass/lib/sass/tree/node.rb +18 -304
  56. data/vendor/sass/lib/sass/tree/prop_node.rb +24 -92
  57. data/vendor/sass/lib/sass/tree/return_node.rb +18 -0
  58. data/vendor/sass/lib/sass/tree/root_node.rb +4 -133
  59. data/vendor/sass/lib/sass/tree/rule_node.rb +21 -164
  60. data/vendor/sass/lib/sass/tree/variable_node.rb +14 -23
  61. data/vendor/sass/lib/sass/tree/visitors/base.rb +75 -0
  62. data/vendor/sass/lib/sass/tree/visitors/check_nesting.rb +134 -0
  63. data/vendor/sass/lib/sass/tree/visitors/convert.rb +255 -0
  64. data/vendor/sass/lib/sass/tree/visitors/cssize.rb +175 -0
  65. data/vendor/sass/lib/sass/tree/visitors/perform.rb +301 -0
  66. data/vendor/sass/lib/sass/tree/visitors/to_css.rb +216 -0
  67. data/vendor/sass/lib/sass/tree/warn_node.rb +4 -28
  68. data/vendor/sass/lib/sass/tree/while_node.rb +5 -35
  69. data/vendor/sass/lib/sass/util.rb +0 -50
  70. data/vendor/sass/sass.gemspec +1 -1
  71. data/vendor/sass/test/sass/conversion_test.rb +53 -102
  72. data/vendor/sass/test/sass/engine_test.rb +416 -540
  73. data/vendor/sass/test/sass/functions_test.rb +306 -4
  74. data/vendor/sass/test/sass/importer_test.rb +0 -22
  75. data/vendor/sass/test/sass/plugin_test.rb +51 -21
  76. data/vendor/sass/test/sass/results/if.css +3 -0
  77. data/vendor/sass/test/sass/script_conversion_test.rb +0 -38
  78. data/vendor/sass/test/sass/script_test.rb +19 -4
  79. data/vendor/sass/test/sass/scss/scss_test.rb +32 -11
  80. data/vendor/sass/test/sass/templates/if.sass +11 -0
  81. data/vendor/sass/test/sass/templates/nested_import.sass +2 -0
  82. data/vendor/sass/test/sass/util_test.rb +0 -21
  83. data/vendor/sass/test/test_helper.rb +0 -3
  84. metadata +268 -258
  85. data/vendor/sass/bin/css2sass +0 -13
  86. data/vendor/sass/lib/sass/cache_stores/active_support.rb +0 -28
  87. data/vendor/sass/lib/sass/importers/rails.rb +0 -75
@@ -28,48 +28,5 @@ module Sass::Tree
28
28
  def value
29
29
  "@media #{query}"
30
30
  end
31
-
32
- # Pass on the parent if it's a RuleNode.
33
- #
34
- # @see Node#cssize
35
- def cssize(extends, parent = nil)
36
- _cssize(extends, (parent if [MediaNode, RuleNode].include?(parent.class)))
37
- rescue Sass::SyntaxError => e
38
- e.modify_backtrace(:filename => filename, :line => line)
39
- raise e
40
- end
41
-
42
- protected
43
-
44
- # Merge nested media queries.
45
- #
46
- # @see Node#_cssize
47
- def _cssize(extends, parent)
48
- node = super
49
- media = node.children.select {|c| c.is_a?(MediaNode)}
50
- node.children.reject! {|c| c.is_a?(MediaNode)}
51
- media.each {|n| n.query = "#{query} and #{n.query}"}
52
- (node.children.empty? ? [] : [node]) + media
53
- end
54
-
55
- # If we're passed a parent, bubble it down.
56
- #
57
- # @see Node#cssize
58
- def cssize!(extends, parent)
59
- return super unless parent.is_a?(RuleNode)
60
- new_rule = parent.dup
61
- new_rule.children = self.children
62
- self.children = Array(new_rule.cssize(extends, self))
63
- # If the last child is actually the end of the group,
64
- # the parent's cssize will set it properly
65
- self.children.last.group_end = false unless self.children.empty?
66
- end
67
-
68
- # @see Node#to_s
69
- def _to_s(tabs)
70
- str = super(tabs + self.tabs)
71
- str.gsub!(/\n\Z/, '') unless style == :compressed || group_end
72
- str
73
- end
74
31
  end
75
32
  end
@@ -4,57 +4,24 @@ module Sass
4
4
  #
5
5
  # @see Sass::Tree
6
6
  class MixinDefNode < Node
7
+ # The mixin name.
8
+ # @return [String]
9
+ attr_reader :name
10
+
11
+ # The arguments for the mixin.
12
+ # Each element is a tuple containing the variable for argument
13
+ # and the parse tree for the default value of the argument.
14
+ #
15
+ # @return [Array<(Script::Node, Script::Node)>]
16
+ attr_reader :args
17
+
7
18
  # @param name [String] The mixin name
8
- # @param args [Array<(Script::Node, Script::Node)>] The arguments for the mixin.
9
- # Each element is a tuple containing the variable for argument
10
- # and the parse tree for the default value of the argument
19
+ # @param args [Array<(Script::Node, Script::Node)>] See \{#args}
11
20
  def initialize(name, args)
12
21
  @name = name
13
22
  @args = args
14
23
  super()
15
24
  end
16
-
17
- protected
18
-
19
- # @see Node#to_src
20
- def to_src(tabs, opts, fmt)
21
- args =
22
- if @args.empty?
23
- ""
24
- else
25
- '(' + @args.map do |v, d|
26
- if d
27
- "#{v.to_sass(opts)}: #{d.to_sass(opts)}"
28
- else
29
- v.to_sass(opts)
30
- end
31
- end.join(", ") + ')'
32
- end
33
-
34
- "#{' ' * tabs}#{fmt == :sass ? '=' : '@mixin '}#{dasherize(@name, opts)}#{args}" +
35
- children_to_src(tabs, opts, fmt)
36
- end
37
-
38
- # Loads the mixin into the environment.
39
- #
40
- # @param environment [Sass::Environment] The lexical environment containing
41
- # variable and mixin values
42
- def _perform(environment)
43
- environment.set_mixin(@name, Sass::Mixin.new(@name, @args, environment, children))
44
- []
45
- end
46
-
47
- # Returns an error message if the given child node is invalid,
48
- # and false otherwise.
49
- #
50
- # {ExtendNode}s are valid within {MixinDefNode}s.
51
- #
52
- # @param child [Tree::Node] A potential child node.
53
- # @return [Boolean, String] Whether or not the child node is valid,
54
- # as well as the error message to display if it is invalid
55
- def invalid_child?(child)
56
- super unless child.is_a?(ExtendNode)
57
- end
58
25
  end
59
26
  end
60
27
  end
@@ -7,137 +7,26 @@ module Sass::Tree
7
7
  #
8
8
  # @see Sass::Tree
9
9
  class MixinNode < Node
10
- # @see Node#options=
11
- def options=(opts)
12
- super
13
- @args.each {|a| a.context = :equals} if opts[:sass2]
14
- @keywords.each {|k, v| v.context = :equals} if opts[:sass2]
15
- end
10
+ # The name of the mixin.
11
+ # @return [String]
12
+ attr_reader :name
13
+
14
+ # The arguments to the mixin.
15
+ # @return [Array<Script::Node>]
16
+ attr_reader :args
17
+
18
+ # A hash from keyword argument names to values.
19
+ # @return [{String => Script::Node}]
20
+ attr_reader :keywords
16
21
 
17
22
  # @param name [String] The name of the mixin
18
- # @param args [Array<Script::Node>] The arguments to the mixin
19
- # @param keywords [{String => Script::Node}] A hash from keyword argument names to values
23
+ # @param args [Array<Script::Node>] See \{#args}
24
+ # @param keywords [{String => Script::Node}] See \{#keywords}
20
25
  def initialize(name, args, keywords)
21
26
  @name = name
22
27
  @args = args
23
28
  @keywords = keywords
24
29
  super()
25
30
  end
26
-
27
- # @see Node#cssize
28
- def cssize(extends, parent = nil)
29
- _cssize(extends, parent) # Pass on the parent even if it's not a MixinNode
30
- end
31
-
32
- protected
33
-
34
- # Returns an error message if the given child node is invalid,
35
- # and false otherwise.
36
- #
37
- # {ExtendNode}s are valid within {MixinNode}s.
38
- #
39
- # @param child [Tree::Node] A potential child node
40
- # @return [Boolean, String] Whether or not the child node is valid,
41
- # as well as the error message to display if it is invalid
42
- def invalid_child?(child)
43
- super unless child.is_a?(ExtendNode)
44
- end
45
-
46
- # @see Node#to_src
47
- def to_src(tabs, opts, fmt)
48
- unless @args.empty? && @keywords.empty?
49
- args = @args.map {|a| a.to_sass(opts)}.join(", ")
50
- keywords = @keywords.map {|k, v| "$#{dasherize(k, opts)}: #{v.to_sass(opts)}"}.join(', ')
51
- arglist = "(#{args}#{', ' unless args.empty? || keywords.empty?}#{keywords})"
52
- end
53
- "#{' ' * tabs}#{fmt == :sass ? '+' : '@include '}#{dasherize(@name, opts)}#{arglist}#{semi fmt}\n"
54
- end
55
-
56
- # @see Node#_cssize
57
- def _cssize(extends, parent)
58
- children.map do |c|
59
- parent.check_child! c
60
- c.cssize(extends, parent)
61
- end.flatten
62
- rescue Sass::SyntaxError => e
63
- e.modify_backtrace(:mixin => @name, :filename => filename, :line => line)
64
- e.add_backtrace(:filename => filename, :line => line)
65
- raise e
66
- end
67
-
68
- # Runs the mixin.
69
- #
70
- # @param environment [Sass::Environment] The lexical environment containing
71
- # variable and mixin values
72
- # @raise [Sass::SyntaxError] if there is no mixin with the given name
73
- # @raise [Sass::SyntaxError] if an incorrect number of arguments was passed
74
- # @see Sass::Tree
75
- def perform!(environment)
76
- handle_include_loop!(environment) if environment.mixins_in_use.include?(@name)
77
-
78
- original_env = environment
79
- original_env.push_frame(:filename => filename, :line => line)
80
- original_env.prepare_frame(:mixin => @name)
81
- raise Sass::SyntaxError.new("Undefined mixin '#{@name}'.") unless mixin = environment.mixin(@name)
82
-
83
- passed_args = @args.dup
84
- passed_keywords = @keywords.dup
85
-
86
- raise Sass::SyntaxError.new(<<END.gsub("\n", "")) if mixin.args.size < passed_args.size
87
- Mixin #{@name} takes #{mixin.args.size} argument#{'s' if mixin.args.size != 1}
88
- but #{@args.size} #{@args.size == 1 ? 'was' : 'were'} passed.
89
- END
90
-
91
- passed_keywords.each do |name, value|
92
- # TODO: Make this fast
93
- unless mixin.args.find {|(var, default)| var.underscored_name == name}
94
- raise Sass::SyntaxError.new("Mixin #{@name} doesn't have an argument named $#{name}")
95
- end
96
- end
97
-
98
- environment = mixin.args.zip(passed_args).
99
- inject(Sass::Environment.new(mixin.environment)) do |env, ((var, default), value)|
100
- env.set_local_var(var.name,
101
- if value
102
- value.perform(environment)
103
- elsif kv = passed_keywords[var.underscored_name]
104
- kv.perform(env)
105
- elsif default
106
- val = default.perform(env)
107
- if default.context == :equals && val.is_a?(Sass::Script::String)
108
- val = Sass::Script::String.new(val.value)
109
- end
110
- val
111
- end)
112
- raise Sass::SyntaxError.new("Mixin #{@name} is missing parameter #{var.inspect}.") unless env.var(var.name)
113
- env
114
- end
115
-
116
- self.children = mixin.tree.map {|c| c.perform(environment)}.flatten
117
- rescue Sass::SyntaxError => e
118
- if original_env # Don't add backtrace info if this is an @include loop
119
- e.modify_backtrace(:mixin => @name, :line => @line)
120
- e.add_backtrace(:line => @line)
121
- end
122
- raise e
123
- ensure
124
- original_env.pop_frame if original_env
125
- end
126
-
127
- private
128
-
129
- def handle_include_loop!(environment)
130
- msg = "An @include loop has been found:"
131
- mixins = environment.stack.map {|s| s[:mixin]}.compact
132
- if mixins.size == 2 && mixins[0] == mixins[1]
133
- raise Sass::SyntaxError.new("#{msg} #{@name} includes itself")
134
- end
135
-
136
- mixins << @name
137
- msg << "\n" << Sass::Util.enum_cons(mixins, 2).map do |m1, m2|
138
- " #{m1} includes #{m2}"
139
- end.join("\n")
140
- raise Sass::SyntaxError.new(msg)
141
- end
142
31
  end
143
32
  end
@@ -8,7 +8,7 @@ module Sass
8
8
  # in addition to nodes for CSS rules and properties.
9
9
  # Nodes that only appear in this state are called **dynamic nodes**.
10
10
  #
11
- # {Tree::Node#perform} returns a static Sass tree, which is different.
11
+ # {Tree::Visitors::Perform} creates a static Sass tree, which is different.
12
12
  # It still has nodes for CSS rules and properties
13
13
  # but it doesn't have any dynamic-generation-related nodes.
14
14
  # The nodes in this state are in the same structure as the Sass document:
@@ -16,12 +16,12 @@ module Sass
16
16
  # Nodes that can be in this state or in the dynamic state
17
17
  # are called **static nodes**.
18
18
  #
19
- # {Tree::Node#cssize} then returns a static CSS tree.
19
+ # {Tree::Visitors::Cssize} is then used to create a static CSS tree.
20
20
  # This is like a static Sass tree,
21
21
  # but the structure exactly mirrors that of the generated CSS.
22
22
  # Rules and properties can't be nested beneath one another in this state.
23
23
  #
24
- # Finally, {Tree::Node#to_s} can be called on a static CSS tree
24
+ # Finally, {Tree::Visitors::ToCss} can be called on a static CSS tree
25
25
  # to get the actual CSS code as a string.
26
26
  module Tree
27
27
  # The abstract superclass of all parse-tree nodes.
@@ -86,29 +86,16 @@ module Sass
86
86
  #
87
87
  # @param child [Tree::Node, Array<Tree::Node>] The child node or nodes
88
88
  # @raise [Sass::SyntaxError] if `child` is invalid
89
- # @see #invalid_child?
90
89
  def <<(child)
91
90
  return if child.nil?
92
91
  if child.is_a?(Array)
93
92
  child.each {|c| self << c}
94
93
  else
95
- check_child! child
96
94
  self.has_children = true
97
95
  @children << child
98
96
  end
99
97
  end
100
98
 
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
99
  # Compares this node and another object (only other {Tree::Node}s will be equal).
113
100
  # This does a structural comparison;
114
101
  # if the contents of the nodes and all the child nodes are equivalent,
@@ -140,22 +127,13 @@ module Sass
140
127
 
141
128
  # Computes the CSS corresponding to this static CSS tree.
142
129
  #
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
130
  # @return [String, nil] The resulting CSS
150
131
  # @see Sass::Tree
151
- def to_s(opts = nil)
152
- _to_s(opts)
153
- rescue Sass::SyntaxError => e
154
- e.modify_backtrace(:filename => filename, :line => line)
155
- raise e
132
+ def to_s
133
+ Sass::Tree::Visitors::ToCss.visit(self)
156
134
  end
157
135
 
158
- # Converts a static CSS tree (e.g. the output of \{#cssize})
136
+ # Converts a static CSS tree (e.g. the output of \{Tree::Visitors::Cssize})
159
137
  # into another static CSS tree,
160
138
  # with the given extensions applied to all relevant {RuleNode}s.
161
139
  #
@@ -176,46 +154,6 @@ module Sass
176
154
  raise e
177
155
  end
178
156
 
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
157
  # Iterates through each node in the tree rooted at this node
220
158
  # in a pre-order walk.
221
159
  #
@@ -228,145 +166,31 @@ module Sass
228
166
 
229
167
  # Converts a node to Sass code that will generate it.
230
168
  #
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})
169
+ # @param options [{Symbol => Object}] An options hash (see {Sass::CSS#initialize})
233
170
  # @return [String] The Sass code corresponding to the node
234
- def to_sass(tabs = 0, opts = {})
235
- to_src(tabs, opts, :sass)
171
+ def to_sass(options = {})
172
+ Sass::Tree::Visitors::Convert.visit(self, options, :sass)
236
173
  end
237
174
 
238
175
  # Converts a node to SCSS code that will generate it.
239
176
  #
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})
177
+ # @param options [{Symbol => Object}] An options hash (see {Sass::CSS#initialize})
242
178
  # @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
179
+ def to_scss(options = {})
180
+ Sass::Tree::Visitors::Convert.visit(self, options, :scss)
318
181
  end
319
182
 
320
- # Runs any dynamic Sass code in this particular node.
321
- # This doesn't modify this node or any of its children.
183
+ # Return a deep clone of this node.
184
+ # The child nodes are cloned, but options are not.
322
185
  #
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)
186
+ # @return [Node]
187
+ def deep_copy
329
188
  node = dup
330
- node.perform!(environment)
189
+ node.children = children.map {|c| c.deep_copy}
331
190
  node
332
191
  end
333
192
 
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
193
+ protected
370
194
 
371
195
  # @see Sass::Shared.balance
372
196
  # @raise [Sass::SyntaxError] if the brackets aren't balanced
@@ -375,116 +199,6 @@ module Sass
375
199
  return res if res
376
200
  raise Sass::SyntaxError.new("Unbalanced brackets.", :line => line)
377
201
  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
202
  end
489
203
  end
490
204
  end