sass 3.3.0.alpha.149 → 3.3.0.alpha.162
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.
- data/REVISION +1 -1
- data/VERSION +1 -1
- data/VERSION_DATE +1 -1
- data/lib/sass/css.rb +1 -1
- data/lib/sass/engine.rb +4 -4
- data/lib/sass/environment.rb +1 -1
- data/lib/sass/exec.rb +1 -1
- data/lib/sass/media.rb +15 -15
- data/lib/sass/script.rb +32 -7
- data/lib/sass/script/css_lexer.rb +2 -2
- data/lib/sass/script/css_parser.rb +1 -1
- data/lib/sass/script/functions.rb +246 -232
- data/lib/sass/script/lexer.rb +24 -32
- data/lib/sass/script/parser.rb +84 -65
- data/lib/sass/script/tree.rb +14 -0
- data/lib/sass/script/tree/funcall.rb +242 -0
- data/lib/sass/script/{interpolation.rb → tree/interpolation.rb} +30 -13
- data/lib/sass/script/tree/list_literal.rb +65 -0
- data/lib/sass/script/tree/literal.rb +46 -0
- data/lib/sass/script/{node.rb → tree/node.rb} +10 -10
- data/lib/sass/script/{operation.rb → tree/operation.rb} +16 -27
- data/lib/sass/script/{string_interpolation.rb → tree/string_interpolation.rb} +4 -4
- data/lib/sass/script/{unary_operation.rb → tree/unary_operation.rb} +7 -8
- data/lib/sass/script/tree/variable.rb +56 -0
- data/lib/sass/script/value.rb +10 -0
- data/lib/sass/script/{arg_list.rb → value/arg_list.rb} +5 -20
- data/lib/sass/script/value/base.rb +222 -0
- data/lib/sass/script/{bool.rb → value/bool.rb} +2 -2
- data/lib/sass/script/{color.rb → value/color.rb} +22 -20
- data/lib/sass/script/{list.rb → value/list.rb} +15 -28
- data/lib/sass/script/{null.rb → value/null.rb} +3 -3
- data/lib/sass/script/{number.rb → value/number.rb} +19 -19
- data/lib/sass/script/{string.rb → value/string.rb} +7 -7
- data/lib/sass/scss/parser.rb +14 -4
- data/lib/sass/selector.rb +26 -26
- data/lib/sass/selector/abstract_sequence.rb +1 -1
- data/lib/sass/selector/simple.rb +6 -7
- data/lib/sass/source/position.rb +13 -0
- data/lib/sass/supports.rb +4 -4
- data/lib/sass/tree/comment_node.rb +3 -3
- data/lib/sass/tree/css_import_node.rb +7 -7
- data/lib/sass/tree/debug_node.rb +2 -2
- data/lib/sass/tree/directive_node.rb +2 -2
- data/lib/sass/tree/each_node.rb +2 -2
- data/lib/sass/tree/extend_node.rb +4 -4
- data/lib/sass/tree/for_node.rb +4 -4
- data/lib/sass/tree/function_node.rb +4 -4
- data/lib/sass/tree/media_node.rb +3 -3
- data/lib/sass/tree/mixin_def_node.rb +4 -4
- data/lib/sass/tree/mixin_node.rb +6 -6
- data/lib/sass/tree/prop_node.rb +23 -15
- data/lib/sass/tree/return_node.rb +2 -2
- data/lib/sass/tree/rule_node.rb +3 -3
- data/lib/sass/tree/variable_node.rb +2 -2
- data/lib/sass/tree/visitors/convert.rb +2 -2
- data/lib/sass/tree/visitors/deep_copy.rb +5 -5
- data/lib/sass/tree/visitors/perform.rb +7 -7
- data/lib/sass/tree/visitors/set_options.rb +6 -6
- data/lib/sass/tree/visitors/to_css.rb +1 -1
- data/lib/sass/tree/warn_node.rb +2 -2
- data/lib/sass/tree/while_node.rb +2 -2
- data/lib/sass/util.rb +2 -2
- data/test/sass/engine_test.rb +6 -6
- data/test/sass/functions_test.rb +20 -20
- data/test/sass/plugin_test.rb +2 -2
- data/test/sass/script_test.rb +38 -29
- data/test/test_helper.rb +1 -1
- metadata +23 -19
- data/lib/sass/script/funcall.rb +0 -238
- data/lib/sass/script/literal.rb +0 -221
- data/lib/sass/script/variable.rb +0 -58
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sass
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 592302665
|
5
5
|
prerelease: 6
|
6
6
|
segments:
|
7
7
|
- 3
|
8
8
|
- 3
|
9
9
|
- 0
|
10
10
|
- alpha
|
11
|
-
-
|
12
|
-
version: 3.3.0.alpha.
|
11
|
+
- 162
|
12
|
+
version: 3.3.0.alpha.162
|
13
13
|
platform: ruby
|
14
14
|
authors:
|
15
15
|
- Nathan Weizenbaum
|
@@ -19,7 +19,7 @@ autorequire:
|
|
19
19
|
bindir: bin
|
20
20
|
cert_chain: []
|
21
21
|
|
22
|
-
date: 2013-05-
|
22
|
+
date: 2013-05-29 00:00:00 -04:00
|
23
23
|
default_executable:
|
24
24
|
dependencies:
|
25
25
|
- !ruby/object:Gem::Dependency
|
@@ -113,26 +113,30 @@ files:
|
|
113
113
|
- lib/sass/repl.rb
|
114
114
|
- lib/sass/root.rb
|
115
115
|
- lib/sass/script.rb
|
116
|
-
- lib/sass/script/arg_list.rb
|
117
|
-
- lib/sass/script/bool.rb
|
118
|
-
- lib/sass/script/color.rb
|
119
116
|
- lib/sass/script/css_lexer.rb
|
120
117
|
- lib/sass/script/css_parser.rb
|
121
|
-
- lib/sass/script/funcall.rb
|
122
118
|
- lib/sass/script/functions.rb
|
123
|
-
- lib/sass/script/interpolation.rb
|
124
119
|
- lib/sass/script/lexer.rb
|
125
|
-
- lib/sass/script/list.rb
|
126
|
-
- lib/sass/script/literal.rb
|
127
|
-
- lib/sass/script/node.rb
|
128
|
-
- lib/sass/script/null.rb
|
129
|
-
- lib/sass/script/number.rb
|
130
|
-
- lib/sass/script/operation.rb
|
131
120
|
- lib/sass/script/parser.rb
|
132
|
-
- lib/sass/script/
|
133
|
-
- lib/sass/script/
|
134
|
-
- lib/sass/script/
|
135
|
-
- lib/sass/script/
|
121
|
+
- lib/sass/script/tree.rb
|
122
|
+
- lib/sass/script/tree/funcall.rb
|
123
|
+
- lib/sass/script/tree/interpolation.rb
|
124
|
+
- lib/sass/script/tree/list_literal.rb
|
125
|
+
- lib/sass/script/tree/literal.rb
|
126
|
+
- lib/sass/script/tree/node.rb
|
127
|
+
- lib/sass/script/tree/operation.rb
|
128
|
+
- lib/sass/script/tree/string_interpolation.rb
|
129
|
+
- lib/sass/script/tree/unary_operation.rb
|
130
|
+
- lib/sass/script/tree/variable.rb
|
131
|
+
- lib/sass/script/value.rb
|
132
|
+
- lib/sass/script/value/arg_list.rb
|
133
|
+
- lib/sass/script/value/base.rb
|
134
|
+
- lib/sass/script/value/bool.rb
|
135
|
+
- lib/sass/script/value/color.rb
|
136
|
+
- lib/sass/script/value/list.rb
|
137
|
+
- lib/sass/script/value/null.rb
|
138
|
+
- lib/sass/script/value/number.rb
|
139
|
+
- lib/sass/script/value/string.rb
|
136
140
|
- lib/sass/scss.rb
|
137
141
|
- lib/sass/scss/css_parser.rb
|
138
142
|
- lib/sass/scss/parser.rb
|
data/lib/sass/script/funcall.rb
DELETED
@@ -1,238 +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
|
-
arg_to_sass = lambda do |arg|
|
58
|
-
sass = arg.to_sass(opts)
|
59
|
-
sass = "(#{sass})" if arg.is_a?(Sass::Script::List) && arg.separator == :comma
|
60
|
-
sass
|
61
|
-
end
|
62
|
-
|
63
|
-
args = @args.map(&arg_to_sass).join(', ')
|
64
|
-
keywords = Sass::Util.hash_to_a(@keywords).
|
65
|
-
map {|k, v| "$#{dasherize(k, opts)}: #{arg_to_sass[v]}"}.join(', ')
|
66
|
-
if self.splat
|
67
|
-
splat = (args.empty? && keywords.empty?) ? "" : ", "
|
68
|
-
splat = "#{splat}#{arg_to_sass[self.splat]}..."
|
69
|
-
end
|
70
|
-
"#{dasherize(name, opts)}(#{args}#{', ' unless args.empty? || keywords.empty?}#{keywords}#{splat})"
|
71
|
-
end
|
72
|
-
|
73
|
-
# Returns the arguments to the function.
|
74
|
-
#
|
75
|
-
# @return [Array<Node>]
|
76
|
-
# @see Node#children
|
77
|
-
def children
|
78
|
-
res = @args + @keywords.values
|
79
|
-
res << @splat if @splat
|
80
|
-
res
|
81
|
-
end
|
82
|
-
|
83
|
-
# @see Node#deep_copy
|
84
|
-
def deep_copy
|
85
|
-
node = dup
|
86
|
-
node.instance_variable_set('@args', args.map {|a| a.deep_copy})
|
87
|
-
node.instance_variable_set('@keywords', Hash[keywords.map {|k, v| [k, v.deep_copy]}])
|
88
|
-
node
|
89
|
-
end
|
90
|
-
|
91
|
-
protected
|
92
|
-
|
93
|
-
# Evaluates the function call.
|
94
|
-
#
|
95
|
-
# @param environment [Sass::Environment] The environment in which to evaluate the SassScript
|
96
|
-
# @return [Literal] The SassScript object that is the value of the function call
|
97
|
-
# @raise [Sass::SyntaxError] if the function call raises an ArgumentError
|
98
|
-
def _perform(environment)
|
99
|
-
args = @args.map {|a| a.perform(environment)}
|
100
|
-
splat = @splat.perform(environment) if @splat
|
101
|
-
if fn = environment.function(@name)
|
102
|
-
keywords = Sass::Util.map_hash(@keywords) {|k, v| [k, v.perform(environment)]}
|
103
|
-
return perform_sass_fn(fn, args, keywords, splat)
|
104
|
-
end
|
105
|
-
|
106
|
-
ruby_name = @name.tr('-', '_')
|
107
|
-
args = construct_ruby_args(ruby_name, args, splat, environment)
|
108
|
-
|
109
|
-
unless Functions.callable?(ruby_name)
|
110
|
-
opts(to_literal(args))
|
111
|
-
else
|
112
|
-
local_environment = Environment.new(environment.global_env, environment.options)
|
113
|
-
opts(Functions::EvaluationContext.new(local_environment).send(ruby_name, *args))
|
114
|
-
end
|
115
|
-
rescue ArgumentError => e
|
116
|
-
message = e.message
|
117
|
-
|
118
|
-
# If this is a legitimate Ruby-raised argument error, re-raise it.
|
119
|
-
# Otherwise, it's an error in the user's stylesheet, so wrap it.
|
120
|
-
if Sass::Util.rbx?
|
121
|
-
# Rubinius has a different error report string than vanilla Ruby. It
|
122
|
-
# also doesn't put the actual method for which the argument error was
|
123
|
-
# thrown in the backtrace, nor does it include `send`, so we look for
|
124
|
-
# `_perform`.
|
125
|
-
if e.message =~ /^method '([^']+)': given (\d+), expected (\d+)/
|
126
|
-
error_name, given, expected = $1, $2, $3
|
127
|
-
raise e if error_name != ruby_name || e.backtrace[0] !~ /:in `_perform'$/
|
128
|
-
message = "wrong number of arguments (#{given} for #{expected})"
|
129
|
-
end
|
130
|
-
elsif Sass::Util.jruby?
|
131
|
-
if Sass::Util.jruby1_6?
|
132
|
-
should_maybe_raise = e.message =~ /^wrong number of arguments \((\d+) for (\d+)\)/ &&
|
133
|
-
# The one case where JRuby does include the Ruby name of the function
|
134
|
-
# is manually-thrown ArgumentErrors, which are indistinguishable from
|
135
|
-
# legitimate ArgumentErrors. We treat both of these as
|
136
|
-
# Sass::SyntaxErrors even though it can hide Ruby errors.
|
137
|
-
e.backtrace[0] !~ /:in `(block in )?#{ruby_name}'$/
|
138
|
-
else
|
139
|
-
should_maybe_raise = e.message =~ /^wrong number of arguments calling `[^`]+` \((\d+) for (\d+)\)/
|
140
|
-
given, expected = $1, $2
|
141
|
-
end
|
142
|
-
|
143
|
-
if should_maybe_raise
|
144
|
-
# JRuby 1.7 includes __send__ before send and _perform.
|
145
|
-
trace = e.backtrace.dup
|
146
|
-
raise e if !Sass::Util.jruby1_6? && trace.shift !~ /:in `__send__'$/
|
147
|
-
|
148
|
-
# JRuby (as of 1.7.2) doesn't put the actual method
|
149
|
-
# for which the argument error was thrown in the backtrace, so we
|
150
|
-
# detect whether our send threw an argument error.
|
151
|
-
if !(trace[0] =~ /:in `send'$/ && trace[1] =~ /:in `_perform'$/)
|
152
|
-
raise e
|
153
|
-
elsif !Sass::Util.jruby1_6?
|
154
|
-
# JRuby 1.7 doesn't use standard formatting for its ArgumentErrors.
|
155
|
-
message = "wrong number of arguments (#{given} for #{expected})"
|
156
|
-
end
|
157
|
-
end
|
158
|
-
elsif e.message =~ /^wrong number of arguments \(\d+ for \d+\)/ &&
|
159
|
-
e.backtrace[0] !~ /:in `(block in )?#{ruby_name}'$/
|
160
|
-
raise e
|
161
|
-
end
|
162
|
-
raise Sass::SyntaxError.new("#{message} for `#{name}'")
|
163
|
-
end
|
164
|
-
|
165
|
-
# This method is factored out from `_perform` so that compass can override
|
166
|
-
# it with a cross-browser implementation for functions that require vendor prefixes
|
167
|
-
# in the generated css.
|
168
|
-
def to_literal(args)
|
169
|
-
Script::String.new("#{name}(#{args.join(', ')})")
|
170
|
-
end
|
171
|
-
|
172
|
-
private
|
173
|
-
|
174
|
-
def construct_ruby_args(name, args, splat, environment)
|
175
|
-
args += splat.to_a if splat
|
176
|
-
|
177
|
-
# If variable arguments were passed, there won't be any explicit keywords.
|
178
|
-
if splat.is_a?(Sass::Script::ArgList)
|
179
|
-
kwargs_size = splat.keywords.size
|
180
|
-
splat.keywords_accessed = false
|
181
|
-
else
|
182
|
-
kwargs_size = @keywords.size
|
183
|
-
end
|
184
|
-
|
185
|
-
unless signature = Functions.signature(name.to_sym, args.size, kwargs_size)
|
186
|
-
return args if @keywords.empty?
|
187
|
-
raise Sass::SyntaxError.new("Function #{name} doesn't support keyword arguments")
|
188
|
-
end
|
189
|
-
keywords = splat.is_a?(Sass::Script::ArgList) ? splat.keywords :
|
190
|
-
Sass::Util.map_hash(@keywords) {|k, v| [k, v.perform(environment)]}
|
191
|
-
|
192
|
-
# If the user passes more non-keyword args than the function expects,
|
193
|
-
# but it does expect keyword args, Ruby's arg handling won't raise an error.
|
194
|
-
# Since we don't want to make functions think about this,
|
195
|
-
# we'll handle it for them here.
|
196
|
-
if signature.var_kwargs && !signature.var_args && args.size > signature.args.size
|
197
|
-
raise Sass::SyntaxError.new(
|
198
|
-
"#{args[signature.args.size].inspect} is not a keyword argument for `#{name}'")
|
199
|
-
elsif keywords.empty?
|
200
|
-
return args
|
201
|
-
end
|
202
|
-
|
203
|
-
args = args + signature.args[args.size..-1].map do |argname|
|
204
|
-
if keywords.has_key?(argname)
|
205
|
-
keywords.delete(argname)
|
206
|
-
else
|
207
|
-
raise Sass::SyntaxError.new("Function #{name} requires an argument named $#{argname}")
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
if keywords.size > 0
|
212
|
-
if signature.var_kwargs
|
213
|
-
args << keywords
|
214
|
-
else
|
215
|
-
argname = keywords.keys.sort.first
|
216
|
-
if signature.args.include?(argname)
|
217
|
-
raise Sass::SyntaxError.new("Function #{name} was passed argument $#{argname} both by position and by name")
|
218
|
-
else
|
219
|
-
raise Sass::SyntaxError.new("Function #{name} doesn't have an argument named $#{argname}")
|
220
|
-
end
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
args
|
225
|
-
end
|
226
|
-
|
227
|
-
def perform_sass_fn(function, args, keywords, splat)
|
228
|
-
Sass::Tree::Visitors::Perform.perform_arguments(function, args, keywords, splat) do |env|
|
229
|
-
val = catch :_sass_return do
|
230
|
-
function.tree.each {|c| Sass::Tree::Visitors::Perform.visit(c, env)}
|
231
|
-
raise Sass::SyntaxError.new("Function #{@name} finished without @return")
|
232
|
-
end
|
233
|
-
val
|
234
|
-
end
|
235
|
-
end
|
236
|
-
end
|
237
|
-
end
|
238
|
-
end
|
data/lib/sass/script/literal.rb
DELETED
@@ -1,221 +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 `=` operation
|
94
|
-
# (used for proprietary MS syntax like `alpha(opacity=20)`).
|
95
|
-
#
|
96
|
-
# @param other [Literal] The right-hand side of the operator
|
97
|
-
# @return [Script::String] A string containing both literals
|
98
|
-
# separated by `"="`
|
99
|
-
def single_eq(other)
|
100
|
-
Sass::Script::String.new("#{self.to_s}=#{other.to_s}")
|
101
|
-
end
|
102
|
-
|
103
|
-
# The SassScript `+` operation.
|
104
|
-
#
|
105
|
-
# @param other [Literal] The right-hand side of the operator
|
106
|
-
# @return [Script::String] A string containing both literals
|
107
|
-
# without any separation
|
108
|
-
def plus(other)
|
109
|
-
if other.is_a?(Sass::Script::String)
|
110
|
-
return Sass::Script::String.new(self.to_s + other.value, other.type)
|
111
|
-
end
|
112
|
-
Sass::Script::String.new(self.to_s + other.to_s)
|
113
|
-
end
|
114
|
-
|
115
|
-
# The SassScript `-` operation.
|
116
|
-
#
|
117
|
-
# @param other [Literal] The right-hand side of the operator
|
118
|
-
# @return [Script::String] A string containing both literals
|
119
|
-
# separated by `"-"`
|
120
|
-
def minus(other)
|
121
|
-
Sass::Script::String.new("#{self.to_s}-#{other.to_s}")
|
122
|
-
end
|
123
|
-
|
124
|
-
# The SassScript `/` operation.
|
125
|
-
#
|
126
|
-
# @param other [Literal] The right-hand side of the operator
|
127
|
-
# @return [Script::String] A string containing both literals
|
128
|
-
# separated by `"/"`
|
129
|
-
def div(other)
|
130
|
-
Sass::Script::String.new("#{self.to_s}/#{other.to_s}")
|
131
|
-
end
|
132
|
-
|
133
|
-
# The SassScript unary `+` operation (e.g. `+$a`).
|
134
|
-
#
|
135
|
-
# @param other [Literal] The right-hand side of the operator
|
136
|
-
# @return [Script::String] A string containing the literal
|
137
|
-
# preceded by `"+"`
|
138
|
-
def unary_plus
|
139
|
-
Sass::Script::String.new("+#{self.to_s}")
|
140
|
-
end
|
141
|
-
|
142
|
-
# The SassScript unary `-` operation (e.g. `-$a`).
|
143
|
-
#
|
144
|
-
# @param other [Literal] The right-hand side of the operator
|
145
|
-
# @return [Script::String] A string containing the literal
|
146
|
-
# preceded by `"-"`
|
147
|
-
def unary_minus
|
148
|
-
Sass::Script::String.new("-#{self.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_div
|
157
|
-
Sass::Script::String.new("/#{self.to_s}")
|
158
|
-
end
|
159
|
-
|
160
|
-
# @return [String] A readable representation of the literal
|
161
|
-
def inspect
|
162
|
-
value.inspect
|
163
|
-
end
|
164
|
-
|
165
|
-
# @return [Boolean] `true` (the Ruby boolean value)
|
166
|
-
def to_bool
|
167
|
-
true
|
168
|
-
end
|
169
|
-
|
170
|
-
# Compares this object with another.
|
171
|
-
#
|
172
|
-
# @param other [Object] The object to compare with
|
173
|
-
# @return [Boolean] Whether or not this literal is equivalent to `other`
|
174
|
-
def ==(other)
|
175
|
-
eq(other).to_bool
|
176
|
-
end
|
177
|
-
|
178
|
-
# @return [Fixnum] The integer value of this literal
|
179
|
-
# @raise [Sass::SyntaxError] if this literal isn't an integer
|
180
|
-
def to_i
|
181
|
-
raise Sass::SyntaxError.new("#{self.inspect} is not an integer.")
|
182
|
-
end
|
183
|
-
|
184
|
-
# @raise [Sass::SyntaxError] if this literal isn't an integer
|
185
|
-
def assert_int!; to_i; end
|
186
|
-
|
187
|
-
# Returns the value of this literal as a list.
|
188
|
-
# Single literals are considered the same as single-element lists.
|
189
|
-
#
|
190
|
-
# @return [Array<Literal>] The of this literal as a list
|
191
|
-
def to_a
|
192
|
-
[self]
|
193
|
-
end
|
194
|
-
|
195
|
-
# Returns the string representation of this literal
|
196
|
-
# as it would be output to the CSS document.
|
197
|
-
#
|
198
|
-
# @return [String]
|
199
|
-
def to_s(opts = {})
|
200
|
-
raise Sass::SyntaxError.new("[BUG] All subclasses of Sass::Literal must implement #to_s.")
|
201
|
-
end
|
202
|
-
alias_method :to_sass, :to_s
|
203
|
-
|
204
|
-
# Returns whether or not this object is null.
|
205
|
-
#
|
206
|
-
# @return [Boolean] `false`
|
207
|
-
def null?
|
208
|
-
false
|
209
|
-
end
|
210
|
-
|
211
|
-
protected
|
212
|
-
|
213
|
-
# Evaluates the literal.
|
214
|
-
#
|
215
|
-
# @param environment [Sass::Environment] The environment in which to evaluate the SassScript
|
216
|
-
# @return [Literal] This literal
|
217
|
-
def _perform(environment)
|
218
|
-
self
|
219
|
-
end
|
220
|
-
end
|
221
|
-
end
|