sass 3.2.7 → 3.3.0.rc.1

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 (184) hide show
  1. data/MIT-LICENSE +2 -2
  2. data/README.md +14 -2
  3. data/Rakefile +25 -1
  4. data/VERSION +1 -1
  5. data/VERSION_DATE +1 -1
  6. data/VERSION_NAME +1 -1
  7. data/lib/sass/cache_stores/base.rb +4 -2
  8. data/lib/sass/cache_stores/chain.rb +2 -1
  9. data/lib/sass/cache_stores/filesystem.rb +2 -6
  10. data/lib/sass/cache_stores/memory.rb +1 -1
  11. data/lib/sass/cache_stores/null.rb +2 -2
  12. data/lib/sass/callbacks.rb +1 -0
  13. data/lib/sass/css.rb +10 -10
  14. data/lib/sass/engine.rb +403 -150
  15. data/lib/sass/environment.rb +136 -57
  16. data/lib/sass/error.rb +7 -7
  17. data/lib/sass/exec.rb +123 -39
  18. data/lib/sass/features.rb +41 -0
  19. data/lib/sass/importers/base.rb +33 -2
  20. data/lib/sass/importers/deprecated_path.rb +45 -0
  21. data/lib/sass/importers/filesystem.rb +25 -14
  22. data/lib/sass/importers.rb +1 -0
  23. data/lib/sass/logger/base.rb +3 -3
  24. data/lib/sass/logger/log_level.rb +4 -6
  25. data/lib/sass/media.rb +19 -19
  26. data/lib/sass/plugin/compiler.rb +141 -101
  27. data/lib/sass/plugin/configuration.rb +18 -22
  28. data/lib/sass/plugin/merb.rb +1 -1
  29. data/lib/sass/plugin/staleness_checker.rb +24 -8
  30. data/lib/sass/plugin.rb +4 -2
  31. data/lib/sass/repl.rb +3 -3
  32. data/lib/sass/script/css_lexer.rb +9 -4
  33. data/lib/sass/script/css_parser.rb +6 -2
  34. data/lib/sass/script/functions.rb +1343 -590
  35. data/lib/sass/script/lexer.rb +84 -52
  36. data/lib/sass/script/parser.rb +217 -97
  37. data/lib/sass/script/tree/funcall.rb +290 -0
  38. data/lib/sass/script/{interpolation.rb → tree/interpolation.rb} +34 -13
  39. data/lib/sass/script/tree/list_literal.rb +80 -0
  40. data/lib/sass/script/tree/literal.rb +47 -0
  41. data/lib/sass/script/tree/map_literal.rb +64 -0
  42. data/lib/sass/script/{node.rb → tree/node.rb} +22 -12
  43. data/lib/sass/script/{operation.rb → tree/operation.rb} +17 -25
  44. data/lib/sass/script/tree/selector.rb +30 -0
  45. data/lib/sass/script/{string_interpolation.rb → tree/string_interpolation.rb} +5 -4
  46. data/lib/sass/script/{unary_operation.rb → tree/unary_operation.rb} +14 -9
  47. data/lib/sass/script/tree/variable.rb +57 -0
  48. data/lib/sass/script/tree.rb +16 -0
  49. data/lib/sass/script/{arg_list.rb → value/arg_list.rb} +4 -24
  50. data/lib/sass/script/value/base.rb +248 -0
  51. data/lib/sass/script/value/bool.rb +36 -0
  52. data/lib/sass/script/{color.rb → value/color.rb} +239 -195
  53. data/lib/sass/script/value/helpers.rb +155 -0
  54. data/lib/sass/script/value/list.rb +119 -0
  55. data/lib/sass/script/value/map.rb +70 -0
  56. data/lib/sass/script/value/null.rb +45 -0
  57. data/lib/sass/script/{number.rb → value/number.rb} +91 -65
  58. data/lib/sass/script/{string.rb → value/string.rb} +9 -11
  59. data/lib/sass/script/value.rb +11 -0
  60. data/lib/sass/script.rb +35 -8
  61. data/lib/sass/scss/css_parser.rb +2 -1
  62. data/lib/sass/scss/parser.rb +338 -170
  63. data/lib/sass/scss/rx.rb +5 -6
  64. data/lib/sass/scss/script_lexer.rb +1 -0
  65. data/lib/sass/scss/script_parser.rb +1 -0
  66. data/lib/sass/scss/static_parser.rb +23 -6
  67. data/lib/sass/selector/abstract_sequence.rb +2 -2
  68. data/lib/sass/selector/comma_sequence.rb +21 -16
  69. data/lib/sass/selector/sequence.rb +60 -34
  70. data/lib/sass/selector/simple.rb +11 -12
  71. data/lib/sass/selector/simple_sequence.rb +55 -33
  72. data/lib/sass/selector.rb +52 -48
  73. data/lib/sass/source/map.rb +211 -0
  74. data/lib/sass/source/position.rb +39 -0
  75. data/lib/sass/source/range.rb +41 -0
  76. data/lib/sass/stack.rb +120 -0
  77. data/lib/sass/supports.rb +12 -13
  78. data/lib/sass/tree/at_root_node.rb +82 -0
  79. data/lib/sass/tree/comment_node.rb +3 -3
  80. data/lib/sass/tree/css_import_node.rb +11 -11
  81. data/lib/sass/tree/debug_node.rb +2 -2
  82. data/lib/sass/tree/directive_node.rb +13 -2
  83. data/lib/sass/tree/each_node.rb +8 -8
  84. data/lib/sass/tree/extend_node.rb +13 -6
  85. data/lib/sass/tree/for_node.rb +4 -4
  86. data/lib/sass/tree/function_node.rb +5 -4
  87. data/lib/sass/tree/if_node.rb +1 -1
  88. data/lib/sass/tree/import_node.rb +4 -5
  89. data/lib/sass/tree/media_node.rb +4 -14
  90. data/lib/sass/tree/mixin_def_node.rb +4 -4
  91. data/lib/sass/tree/mixin_node.rb +21 -8
  92. data/lib/sass/tree/node.rb +29 -12
  93. data/lib/sass/tree/prop_node.rb +38 -18
  94. data/lib/sass/tree/return_node.rb +3 -2
  95. data/lib/sass/tree/root_node.rb +19 -3
  96. data/lib/sass/tree/rule_node.rb +25 -17
  97. data/lib/sass/tree/supports_node.rb +0 -13
  98. data/lib/sass/tree/trace_node.rb +2 -1
  99. data/lib/sass/tree/variable_node.rb +9 -3
  100. data/lib/sass/tree/visitors/base.rb +6 -6
  101. data/lib/sass/tree/visitors/check_nesting.rb +12 -9
  102. data/lib/sass/tree/visitors/convert.rb +63 -38
  103. data/lib/sass/tree/visitors/cssize.rb +63 -23
  104. data/lib/sass/tree/visitors/deep_copy.rb +6 -5
  105. data/lib/sass/tree/visitors/extend.rb +7 -7
  106. data/lib/sass/tree/visitors/perform.rb +256 -151
  107. data/lib/sass/tree/visitors/set_options.rb +6 -6
  108. data/lib/sass/tree/visitors/to_css.rb +231 -81
  109. data/lib/sass/tree/warn_node.rb +2 -2
  110. data/lib/sass/tree/while_node.rb +2 -2
  111. data/lib/sass/util/multibyte_string_scanner.rb +2 -0
  112. data/lib/sass/util/normalized_map.rb +65 -0
  113. data/lib/sass/util/ordered_hash.rb +188 -0
  114. data/lib/sass/util/subset_map.rb +3 -2
  115. data/lib/sass/util/test.rb +9 -0
  116. data/lib/sass/util.rb +220 -34
  117. data/lib/sass/version.rb +9 -9
  118. data/lib/sass.rb +14 -7
  119. data/test/sass/compiler_test.rb +213 -0
  120. data/test/sass/conversion_test.rb +235 -9
  121. data/test/sass/engine_test.rb +230 -60
  122. data/test/sass/exec_test.rb +86 -0
  123. data/test/sass/extend_test.rb +215 -147
  124. data/test/sass/functions_test.rb +584 -99
  125. data/test/sass/importer_test.rb +165 -17
  126. data/test/sass/plugin_test.rb +19 -13
  127. data/test/sass/script_conversion_test.rb +40 -0
  128. data/test/sass/script_test.rb +231 -21
  129. data/test/sass/scss/css_test.rb +14 -5
  130. data/test/sass/scss/scss_test.rb +1266 -66
  131. data/test/sass/source_map_test.rb +879 -0
  132. data/test/sass/templates/bork5.sass +3 -0
  133. data/test/sass/util/normalized_map_test.rb +30 -0
  134. data/test/sass/util_test.rb +90 -0
  135. data/test/sass/value_helpers_test.rb +181 -0
  136. data/test/test_helper.rb +7 -2
  137. metadata +316 -291
  138. data/lib/sass/script/bool.rb +0 -18
  139. data/lib/sass/script/funcall.rb +0 -231
  140. data/lib/sass/script/list.rb +0 -84
  141. data/lib/sass/script/literal.rb +0 -239
  142. data/lib/sass/script/null.rb +0 -34
  143. data/lib/sass/script/variable.rb +0 -58
  144. data/test/Gemfile +0 -3
  145. data/vendor/listen/CHANGELOG.md +0 -221
  146. data/vendor/listen/CONTRIBUTING.md +0 -38
  147. data/vendor/listen/Gemfile +0 -30
  148. data/vendor/listen/Guardfile +0 -8
  149. data/vendor/listen/LICENSE +0 -20
  150. data/vendor/listen/README.md +0 -315
  151. data/vendor/listen/Rakefile +0 -47
  152. data/vendor/listen/Vagrantfile +0 -96
  153. data/vendor/listen/lib/listen/adapter.rb +0 -214
  154. data/vendor/listen/lib/listen/adapters/bsd.rb +0 -112
  155. data/vendor/listen/lib/listen/adapters/darwin.rb +0 -85
  156. data/vendor/listen/lib/listen/adapters/linux.rb +0 -113
  157. data/vendor/listen/lib/listen/adapters/polling.rb +0 -67
  158. data/vendor/listen/lib/listen/adapters/windows.rb +0 -87
  159. data/vendor/listen/lib/listen/dependency_manager.rb +0 -126
  160. data/vendor/listen/lib/listen/directory_record.rb +0 -371
  161. data/vendor/listen/lib/listen/listener.rb +0 -225
  162. data/vendor/listen/lib/listen/multi_listener.rb +0 -143
  163. data/vendor/listen/lib/listen/turnstile.rb +0 -28
  164. data/vendor/listen/lib/listen/version.rb +0 -3
  165. data/vendor/listen/lib/listen.rb +0 -40
  166. data/vendor/listen/listen.gemspec +0 -22
  167. data/vendor/listen/spec/listen/adapter_spec.rb +0 -183
  168. data/vendor/listen/spec/listen/adapters/bsd_spec.rb +0 -36
  169. data/vendor/listen/spec/listen/adapters/darwin_spec.rb +0 -37
  170. data/vendor/listen/spec/listen/adapters/linux_spec.rb +0 -47
  171. data/vendor/listen/spec/listen/adapters/polling_spec.rb +0 -68
  172. data/vendor/listen/spec/listen/adapters/windows_spec.rb +0 -30
  173. data/vendor/listen/spec/listen/dependency_manager_spec.rb +0 -107
  174. data/vendor/listen/spec/listen/directory_record_spec.rb +0 -1225
  175. data/vendor/listen/spec/listen/listener_spec.rb +0 -169
  176. data/vendor/listen/spec/listen/multi_listener_spec.rb +0 -174
  177. data/vendor/listen/spec/listen/turnstile_spec.rb +0 -56
  178. data/vendor/listen/spec/listen_spec.rb +0 -73
  179. data/vendor/listen/spec/spec_helper.rb +0 -21
  180. data/vendor/listen/spec/support/adapter_helper.rb +0 -629
  181. data/vendor/listen/spec/support/directory_record_helper.rb +0 -55
  182. data/vendor/listen/spec/support/fixtures_helper.rb +0 -29
  183. data/vendor/listen/spec/support/listeners_helper.rb +0 -156
  184. data/vendor/listen/spec/support/platform_helper.rb +0 -15
@@ -1,18 +0,0 @@
1
- require 'sass/script/literal'
2
-
3
- module Sass::Script
4
- # A SassScript object representing a boolean (true or false) value.
5
- class Bool < Literal
6
- # The Ruby value of the boolean.
7
- #
8
- # @return [Boolean]
9
- attr_reader :value
10
- alias_method :to_bool, :value
11
-
12
- # @return [String] "true" or "false"
13
- def to_s(opts = {})
14
- @value.to_s
15
- end
16
- alias_method :to_sass, :to_s
17
- end
18
- end
@@ -1,231 +0,0 @@
1
- require 'sass/script/functions'
2
-
3
- module Sass
4
- module Script
5
- # A SassScript parse node representing a function call.
6
- #
7
- # A function call either calls one of the functions in {Script::Functions},
8
- # or if no function with the given name exists
9
- # it returns a string representation of the function call.
10
- class Funcall < Node
11
- # The name of the function.
12
- #
13
- # @return [String]
14
- attr_reader :name
15
-
16
- # The arguments to the function.
17
- #
18
- # @return [Array<Script::Node>]
19
- attr_reader :args
20
-
21
- # The keyword arguments to the function.
22
- #
23
- # @return [{String => Script::Node}]
24
- attr_reader :keywords
25
-
26
- # The splat argument for this function, if one exists.
27
- #
28
- # @return [Script::Node?]
29
- attr_accessor :splat
30
-
31
- # @param name [String] See \{#name}
32
- # @param args [Array<Script::Node>] See \{#args}
33
- # @param splat [Script::Node] See \{#splat}
34
- # @param keywords [{String => Script::Node}] See \{#keywords}
35
- def initialize(name, args, keywords, splat)
36
- @name = name
37
- @args = args
38
- @keywords = keywords
39
- @splat = splat
40
- super()
41
- end
42
-
43
- # @return [String] A string representation of the function call
44
- def inspect
45
- args = @args.map {|a| a.inspect}.join(', ')
46
- keywords = Sass::Util.hash_to_a(@keywords).
47
- map {|k, v| "$#{k}: #{v.inspect}"}.join(', ')
48
- if self.splat
49
- splat = (args.empty? && keywords.empty?) ? "" : ", "
50
- splat = "#{splat}#{self.splat.inspect}..."
51
- end
52
- "#{name}(#{args}#{', ' unless args.empty? || keywords.empty?}#{keywords}#{splat})"
53
- end
54
-
55
- # @see Node#to_sass
56
- def to_sass(opts = {})
57
- args = @args.map {|a| a.to_sass(opts)}.join(', ')
58
- keywords = Sass::Util.hash_to_a(@keywords).
59
- map {|k, v| "$#{dasherize(k, opts)}: #{v.to_sass(opts)}"}.join(', ')
60
- if self.splat
61
- splat = (args.empty? && keywords.empty?) ? "" : ", "
62
- splat = "#{splat}#{self.splat.inspect}..."
63
- end
64
- "#{dasherize(name, opts)}(#{args}#{', ' unless args.empty? || keywords.empty?}#{keywords}#{splat})"
65
- end
66
-
67
- # Returns the arguments to the function.
68
- #
69
- # @return [Array<Node>]
70
- # @see Node#children
71
- def children
72
- res = @args + @keywords.values
73
- res << @splat if @splat
74
- res
75
- end
76
-
77
- # @see Node#deep_copy
78
- def deep_copy
79
- node = dup
80
- node.instance_variable_set('@args', args.map {|a| a.deep_copy})
81
- node.instance_variable_set('@keywords', Hash[keywords.map {|k, v| [k, v.deep_copy]}])
82
- node
83
- end
84
-
85
- protected
86
-
87
- # Evaluates the function call.
88
- #
89
- # @param environment [Sass::Environment] The environment in which to evaluate the SassScript
90
- # @return [Literal] The SassScript object that is the value of the function call
91
- # @raise [Sass::SyntaxError] if the function call raises an ArgumentError
92
- def _perform(environment)
93
- args = @args.map {|a| a.perform(environment)}
94
- splat = @splat.perform(environment) if @splat
95
- if fn = environment.function(@name)
96
- keywords = Sass::Util.map_hash(@keywords) {|k, v| [k, v.perform(environment)]}
97
- return perform_sass_fn(fn, args, keywords, splat)
98
- end
99
-
100
- ruby_name = @name.tr('-', '_')
101
- args = construct_ruby_args(ruby_name, args, splat, environment)
102
-
103
- unless Functions.callable?(ruby_name)
104
- opts(to_literal(args))
105
- else
106
- opts(Functions::EvaluationContext.new(environment.options).send(ruby_name, *args))
107
- end
108
- rescue ArgumentError => e
109
- message = e.message
110
-
111
- # If this is a legitimate Ruby-raised argument error, re-raise it.
112
- # Otherwise, it's an error in the user's stylesheet, so wrap it.
113
- if Sass::Util.rbx?
114
- # Rubinius has a different error report string than vanilla Ruby. It
115
- # also doesn't put the actual method for which the argument error was
116
- # thrown in the backtrace, nor does it include `send`, so we look for
117
- # `_perform`.
118
- if e.message =~ /^method '([^']+)': given (\d+), expected (\d+)/
119
- error_name, given, expected = $1, $2, $3
120
- raise e if error_name != ruby_name || e.backtrace[0] !~ /:in `_perform'$/
121
- message = "wrong number of arguments (#{given} for #{expected})"
122
- end
123
- elsif Sass::Util.jruby?
124
- if Sass::Util.jruby1_6?
125
- should_maybe_raise = e.message =~ /^wrong number of arguments \((\d+) for (\d+)\)/ &&
126
- # The one case where JRuby does include the Ruby name of the function
127
- # is manually-thrown ArgumentErrors, which are indistinguishable from
128
- # legitimate ArgumentErrors. We treat both of these as
129
- # Sass::SyntaxErrors even though it can hide Ruby errors.
130
- e.backtrace[0] !~ /:in `(block in )?#{ruby_name}'$/
131
- else
132
- should_maybe_raise = e.message =~ /^wrong number of arguments calling `[^`]+` \((\d+) for (\d+)\)/
133
- given, expected = $1, $2
134
- end
135
-
136
- if should_maybe_raise
137
- # JRuby 1.7 includes __send__ before send and _perform.
138
- trace = e.backtrace.dup
139
- raise e if !Sass::Util.jruby1_6? && trace.shift !~ /:in `__send__'$/
140
-
141
- # JRuby (as of 1.7.2) doesn't put the actual method
142
- # for which the argument error was thrown in the backtrace, so we
143
- # detect whether our send threw an argument error.
144
- if !(trace[0] =~ /:in `send'$/ && trace[1] =~ /:in `_perform'$/)
145
- raise e
146
- elsif !Sass::Util.jruby1_6?
147
- # JRuby 1.7 doesn't use standard formatting for its ArgumentErrors.
148
- message = "wrong number of arguments (#{given} for #{expected})"
149
- end
150
- end
151
- elsif e.message =~ /^wrong number of arguments \(\d+ for \d+\)/ &&
152
- e.backtrace[0] !~ /:in `(block in )?#{ruby_name}'$/
153
- raise e
154
- end
155
- raise Sass::SyntaxError.new("#{message} for `#{name}'")
156
- end
157
-
158
- # This method is factored out from `_perform` so that compass can override
159
- # it with a cross-browser implementation for functions that require vendor prefixes
160
- # in the generated css.
161
- def to_literal(args)
162
- Script::String.new("#{name}(#{args.join(', ')})")
163
- end
164
-
165
- private
166
-
167
- def construct_ruby_args(name, args, splat, environment)
168
- args += splat.to_a if splat
169
-
170
- # If variable arguments were passed, there won't be any explicit keywords.
171
- if splat.is_a?(Sass::Script::ArgList)
172
- kwargs_size = splat.keywords.size
173
- splat.keywords_accessed = false
174
- else
175
- kwargs_size = @keywords.size
176
- end
177
-
178
- unless signature = Functions.signature(name.to_sym, args.size, kwargs_size)
179
- return args if @keywords.empty?
180
- raise Sass::SyntaxError.new("Function #{name} doesn't support keyword arguments")
181
- end
182
- keywords = splat.is_a?(Sass::Script::ArgList) ? splat.keywords :
183
- Sass::Util.map_hash(@keywords) {|k, v| [k, v.perform(environment)]}
184
-
185
- # If the user passes more non-keyword args than the function expects,
186
- # but it does expect keyword args, Ruby's arg handling won't raise an error.
187
- # Since we don't want to make functions think about this,
188
- # we'll handle it for them here.
189
- if signature.var_kwargs && !signature.var_args && args.size > signature.args.size
190
- raise Sass::SyntaxError.new(
191
- "#{args[signature.args.size].inspect} is not a keyword argument for `#{name}'")
192
- elsif keywords.empty?
193
- return args
194
- end
195
-
196
- args = args + signature.args[args.size..-1].map do |argname|
197
- if keywords.has_key?(argname)
198
- keywords.delete(argname)
199
- else
200
- raise Sass::SyntaxError.new("Function #{name} requires an argument named $#{argname}")
201
- end
202
- end
203
-
204
- if keywords.size > 0
205
- if signature.var_kwargs
206
- args << keywords
207
- else
208
- argname = keywords.keys.sort.first
209
- if signature.args.include?(argname)
210
- raise Sass::SyntaxError.new("Function #{name} was passed argument $#{argname} both by position and by name")
211
- else
212
- raise Sass::SyntaxError.new("Function #{name} doesn't have an argument named $#{argname}")
213
- end
214
- end
215
- end
216
-
217
- args
218
- end
219
-
220
- def perform_sass_fn(function, args, keywords, splat)
221
- Sass::Tree::Visitors::Perform.perform_arguments(function, args, keywords, splat) do |env|
222
- val = catch :_sass_return do
223
- function.tree.each {|c| Sass::Tree::Visitors::Perform.visit(c, env)}
224
- raise Sass::SyntaxError.new("Function #{@name} finished without @return")
225
- end
226
- val
227
- end
228
- end
229
- end
230
- end
231
- end
@@ -1,84 +0,0 @@
1
- module Sass::Script
2
- # A SassScript object representing a CSS list.
3
- # This includes both comma-separated lists and space-separated lists.
4
- class List < Literal
5
- # The Ruby array containing the contents of the list.
6
- #
7
- # @return [Array<Literal>]
8
- attr_reader :value
9
- alias_method :children, :value
10
- alias_method :to_a, :value
11
-
12
- # The operator separating the values of the list.
13
- # Either `:comma` or `:space`.
14
- #
15
- # @return [Symbol]
16
- attr_reader :separator
17
-
18
- # Creates a new list.
19
- #
20
- # @param value [Array<Literal>] See \{#value}
21
- # @param separator [String] See \{#separator}
22
- def initialize(value, separator)
23
- super(value)
24
- @separator = separator
25
- end
26
-
27
- # @see Node#deep_copy
28
- def deep_copy
29
- node = dup
30
- node.instance_variable_set('@value', value.map {|c| c.deep_copy})
31
- node
32
- end
33
-
34
- # @see Node#eq
35
- def eq(other)
36
- Sass::Script::Bool.new(
37
- other.is_a?(List) && self.value == other.value &&
38
- self.separator == other.separator)
39
- end
40
-
41
- # @see Node#to_s
42
- def to_s(opts = {})
43
- raise Sass::SyntaxError.new("() isn't a valid CSS value.") if value.empty?
44
- return value.reject {|e| e.is_a?(Null) || e.is_a?(List) && e.value.empty?}.map {|e| e.to_s(opts)}.join(sep_str)
45
- end
46
-
47
- # @see Node#to_sass
48
- def to_sass(opts = {})
49
- return "()" if value.empty?
50
- precedence = Sass::Script::Parser.precedence_of(separator)
51
- value.reject {|e| e.is_a?(Null)}.map do |v|
52
- if v.is_a?(List) && Sass::Script::Parser.precedence_of(v.separator) <= precedence
53
- "(#{v.to_sass(opts)})"
54
- else
55
- v.to_sass(opts)
56
- end
57
- end.join(sep_str(nil))
58
- end
59
-
60
- # @see Node#inspect
61
- def inspect
62
- "(#{to_sass})"
63
- end
64
-
65
- protected
66
-
67
- # @see Node#_perform
68
- def _perform(environment)
69
- list = Sass::Script::List.new(
70
- value.map {|e| e.perform(environment)},
71
- separator)
72
- list.options = self.options
73
- list
74
- end
75
-
76
- private
77
-
78
- def sep_str(opts = self.options)
79
- return ' ' if separator == :space
80
- return ',' if opts && opts[:style] == :compressed
81
- return ', '
82
- end
83
- end
84
- end
@@ -1,239 +0,0 @@
1
- module Sass::Script
2
- # The abstract superclass for SassScript objects.
3
- #
4
- # Many of these methods, especially the ones that correspond to SassScript operations,
5
- # are designed to be overridden by subclasses which may change the semantics somewhat.
6
- # The operations listed here are just the defaults.
7
- class Literal < Node
8
- require 'sass/script/string'
9
- require 'sass/script/number'
10
- require 'sass/script/color'
11
- require 'sass/script/bool'
12
- require 'sass/script/null'
13
- require 'sass/script/list'
14
- require 'sass/script/arg_list'
15
-
16
- # Returns the Ruby value of the literal.
17
- # The type of this value varies based on the subclass.
18
- #
19
- # @return [Object]
20
- attr_reader :value
21
-
22
- # Creates a new literal.
23
- #
24
- # @param value [Object] The object for \{#value}
25
- def initialize(value = nil)
26
- @value = value
27
- super()
28
- end
29
-
30
- # Returns an empty array.
31
- #
32
- # @return [Array<Node>] empty
33
- # @see Node#children
34
- def children
35
- []
36
- end
37
-
38
- # @see Node#deep_copy
39
- def deep_copy
40
- dup
41
- end
42
-
43
- # Returns the options hash for this node.
44
- #
45
- # @return [{Symbol => Object}]
46
- # @raise [Sass::SyntaxError] if the options hash hasn't been set.
47
- # This should only happen when the literal was created
48
- # outside of the parser and \{#to\_s} was called on it
49
- def options
50
- opts = super
51
- return opts if opts
52
- raise Sass::SyntaxError.new(<<MSG)
53
- The #options attribute is not set on this #{self.class}.
54
- This error is probably occurring because #to_s was called
55
- on this literal within a custom Sass function without first
56
- setting the #option attribute.
57
- MSG
58
- end
59
-
60
- # The SassScript `==` operation.
61
- # **Note that this returns a {Sass::Script::Bool} object,
62
- # not a Ruby boolean**.
63
- #
64
- # @param other [Literal] The right-hand side of the operator
65
- # @return [Bool] True if this literal is the same as the other,
66
- # false otherwise
67
- def eq(other)
68
- Sass::Script::Bool.new(self.class == other.class && self.value == other.value)
69
- end
70
-
71
- # The SassScript `!=` operation.
72
- # **Note that this returns a {Sass::Script::Bool} object,
73
- # not a Ruby boolean**.
74
- #
75
- # @param other [Literal] The right-hand side of the operator
76
- # @return [Bool] False if this literal is the same as the other,
77
- # true otherwise
78
- def neq(other)
79
- Sass::Script::Bool.new(!eq(other).to_bool)
80
- end
81
-
82
- # The SassScript `==` operation.
83
- # **Note that this returns a {Sass::Script::Bool} object,
84
- # not a Ruby boolean**.
85
- #
86
- # @param other [Literal] The right-hand side of the operator
87
- # @return [Bool] True if this literal is the same as the other,
88
- # false otherwise
89
- def unary_not
90
- Sass::Script::Bool.new(!to_bool)
91
- end
92
-
93
- # The SassScript default operation (e.g. `$a $b`, `"foo" "bar"`).
94
- #
95
- # @param other [Literal] The right-hand side of the operator
96
- # @return [Script::String] A string containing both literals
97
- # separated by a space
98
- def space(other)
99
- Sass::Script::String.new("#{self.to_s} #{other.to_s}")
100
- end
101
-
102
- # The SassScript `,` operation (e.g. `$a, $b`, `"foo", "bar"`).
103
- #
104
- # @param other [Literal] The right-hand side of the operator
105
- # @return [Script::String] A string containing both literals
106
- # separated by `", "`
107
- def comma(other)
108
- Sass::Script::String.new("#{self.to_s},#{' ' unless options[:style] == :compressed}#{other.to_s}")
109
- end
110
-
111
- # The SassScript `=` operation
112
- # (used for proprietary MS syntax like `alpha(opacity=20)`).
113
- #
114
- # @param other [Literal] The right-hand side of the operator
115
- # @return [Script::String] A string containing both literals
116
- # separated by `"="`
117
- def single_eq(other)
118
- Sass::Script::String.new("#{self.to_s}=#{other.to_s}")
119
- end
120
-
121
- # The SassScript `+` operation.
122
- #
123
- # @param other [Literal] The right-hand side of the operator
124
- # @return [Script::String] A string containing both literals
125
- # without any separation
126
- def plus(other)
127
- if other.is_a?(Sass::Script::String)
128
- return Sass::Script::String.new(self.to_s + other.value, other.type)
129
- end
130
- Sass::Script::String.new(self.to_s + other.to_s)
131
- end
132
-
133
- # The SassScript `-` operation.
134
- #
135
- # @param other [Literal] The right-hand side of the operator
136
- # @return [Script::String] A string containing both literals
137
- # separated by `"-"`
138
- def minus(other)
139
- Sass::Script::String.new("#{self.to_s}-#{other.to_s}")
140
- end
141
-
142
- # The SassScript `/` operation.
143
- #
144
- # @param other [Literal] The right-hand side of the operator
145
- # @return [Script::String] A string containing both literals
146
- # separated by `"/"`
147
- def div(other)
148
- Sass::Script::String.new("#{self.to_s}/#{other.to_s}")
149
- end
150
-
151
- # The SassScript unary `+` operation (e.g. `+$a`).
152
- #
153
- # @param other [Literal] The right-hand side of the operator
154
- # @return [Script::String] A string containing the literal
155
- # preceded by `"+"`
156
- def unary_plus
157
- Sass::Script::String.new("+#{self.to_s}")
158
- end
159
-
160
- # The SassScript unary `-` operation (e.g. `-$a`).
161
- #
162
- # @param other [Literal] The right-hand side of the operator
163
- # @return [Script::String] A string containing the literal
164
- # preceded by `"-"`
165
- def unary_minus
166
- Sass::Script::String.new("-#{self.to_s}")
167
- end
168
-
169
- # The SassScript unary `/` operation (e.g. `/$a`).
170
- #
171
- # @param other [Literal] The right-hand side of the operator
172
- # @return [Script::String] A string containing the literal
173
- # preceded by `"/"`
174
- def unary_div
175
- Sass::Script::String.new("/#{self.to_s}")
176
- end
177
-
178
- # @return [String] A readable representation of the literal
179
- def inspect
180
- value.inspect
181
- end
182
-
183
- # @return [Boolean] `true` (the Ruby boolean value)
184
- def to_bool
185
- true
186
- end
187
-
188
- # Compares this object with another.
189
- #
190
- # @param other [Object] The object to compare with
191
- # @return [Boolean] Whether or not this literal is equivalent to `other`
192
- def ==(other)
193
- eq(other).to_bool
194
- end
195
-
196
- # @return [Fixnum] The integer value of this literal
197
- # @raise [Sass::SyntaxError] if this literal isn't an integer
198
- def to_i
199
- raise Sass::SyntaxError.new("#{self.inspect} is not an integer.")
200
- end
201
-
202
- # @raise [Sass::SyntaxError] if this literal isn't an integer
203
- def assert_int!; to_i; end
204
-
205
- # Returns the value of this literal as a list.
206
- # Single literals are considered the same as single-element lists.
207
- #
208
- # @return [Array<Literal>] The of this literal as a list
209
- def to_a
210
- [self]
211
- end
212
-
213
- # Returns the string representation of this literal
214
- # as it would be output to the CSS document.
215
- #
216
- # @return [String]
217
- def to_s(opts = {})
218
- raise Sass::SyntaxError.new("[BUG] All subclasses of Sass::Literal must implement #to_s.")
219
- end
220
- alias_method :to_sass, :to_s
221
-
222
- # Returns whether or not this object is null.
223
- #
224
- # @return [Boolean] `false`
225
- def null?
226
- false
227
- end
228
-
229
- protected
230
-
231
- # Evaluates the literal.
232
- #
233
- # @param environment [Sass::Environment] The environment in which to evaluate the SassScript
234
- # @return [Literal] This literal
235
- def _perform(environment)
236
- self
237
- end
238
- end
239
- end
@@ -1,34 +0,0 @@
1
- require 'sass/script/literal'
2
-
3
- module Sass::Script
4
- # A SassScript object representing a null value.
5
- class Null < Literal
6
- # Creates a new null literal.
7
- def initialize
8
- super nil
9
- end
10
-
11
- # @return [Boolean] `false` (the Ruby boolean value)
12
- def to_bool
13
- false
14
- end
15
-
16
- # @return [Boolean] `true`
17
- def null?
18
- true
19
- end
20
-
21
- # @return [String] '' (An empty string)
22
- def to_s(opts = {})
23
- ''
24
- end
25
- alias_method :to_sass, :to_s
26
-
27
- # Returns a string representing a null value.
28
- #
29
- # @return [String]
30
- def inspect
31
- 'null'
32
- end
33
- end
34
- end
@@ -1,58 +0,0 @@
1
- module Sass
2
- module Script
3
- # A SassScript parse node representing a variable.
4
- class Variable < Node
5
- # The name of the variable.
6
- #
7
- # @return [String]
8
- attr_reader :name
9
-
10
- # The underscored name of the variable.
11
- #
12
- # @return [String]
13
- attr_reader :underscored_name
14
-
15
- # @param name [String] See \{#name}
16
- def initialize(name)
17
- @name = name
18
- @underscored_name = name.gsub(/-/,"_")
19
- super()
20
- end
21
-
22
- # @return [String] A string representation of the variable
23
- def inspect(opts = {})
24
- "$#{dasherize(name, opts)}"
25
- end
26
- alias_method :to_sass, :inspect
27
-
28
- # Returns an empty array.
29
- #
30
- # @return [Array<Node>] empty
31
- # @see Node#children
32
- def children
33
- []
34
- end
35
-
36
- # @see Node#deep_copy
37
- def deep_copy
38
- dup
39
- end
40
-
41
- protected
42
-
43
- # Evaluates the variable.
44
- #
45
- # @param environment [Sass::Environment] The environment in which to evaluate the SassScript
46
- # @return [Literal] The SassScript object that is the value of the variable
47
- # @raise [Sass::SyntaxError] if the variable is undefined
48
- def _perform(environment)
49
- raise SyntaxError.new("Undefined variable: \"$#{name}\".") unless val = environment.var(name)
50
- if val.is_a?(Number)
51
- val = val.dup
52
- val.original = nil
53
- end
54
- return val
55
- end
56
- end
57
- end
58
- end
data/test/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source :gemcutter
2
-
3
- gem 'rake'