Class: Sass::Script::Literal
Overview
The abstract superclass for SassScript objects.
Many of these methods, especially the ones that correspond to SassScript operations, are designed to be overridden by subclasses which may change the semantics somewhat. The operations listed here are just the defaults.
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the Ruby value of the literal.
Attributes inherited from Node
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compares this object with another.
-
#_perform(environment) ⇒ Literal
protected
Evaluates the literal.
- #assert_int!
-
#children ⇒ Array<Node>
Returns an empty array.
-
#comma(other) ⇒ Script::String
The SassScript
,
operation (e.g.$a, $b
,"foo", "bar"
). - #deep_copy
-
#div(other) ⇒ Script::String
The SassScript
/
operation. -
#eq(other) ⇒ Bool
The SassScript
==
operation. -
#initialize(value = nil) ⇒ Literal
constructor
Creates a new literal.
-
#inspect ⇒ String
A readable representation of the literal.
-
#minus(other) ⇒ Script::String
The SassScript
-
operation. -
#neq(other) ⇒ Bool
The SassScript
!=
operation. -
#null? ⇒ Boolean
Returns whether or not this object is null.
-
#options ⇒ {Symbol => Object}
Returns the options hash for this node.
-
#plus(other) ⇒ Script::String
The SassScript
+
operation. -
#single_eq(other) ⇒ Script::String
The SassScript
=
operation (used for proprietary MS syntax likealpha(opacity=20)
). -
#space(other) ⇒ Script::String
The SassScript default operation (e.g.
$a $b
,"foo" "bar"
). -
#to_a ⇒ Array<Literal>
Returns the value of this literal as a list.
-
#to_bool ⇒ Boolean
true
(the Ruby boolean value). -
#to_i ⇒ Fixnum
The integer value of this literal.
-
#to_s(opts = {}) ⇒ String
(also: #to_sass)
Returns the string representation of this literal as it would be output to the CSS document.
-
#unary_div ⇒ Script::String
The SassScript unary
/
operation (e.g./$a
). -
#unary_minus ⇒ Script::String
The SassScript unary
-
operation (e.g.-$a
). -
#unary_not ⇒ Bool
The SassScript
==
operation. -
#unary_plus ⇒ Script::String
The SassScript unary
+
operation (e.g.+$a
).
Methods inherited from Node
Constructor Details
#initialize(value = nil) ⇒ Literal
Creates a new literal.
25 26 27 28 |
# File 'lib/sass/script/literal.rb', line 25
def initialize(value = nil)
@value = value
super()
end
|
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the Ruby value of the literal. The type of this value varies based on the subclass.
20 21 22 |
# File 'lib/sass/script/literal.rb', line 20
def value
@value
end
|
Instance Method Details
#==(other) ⇒ Boolean
Compares this object with another.
192 193 194 |
# File 'lib/sass/script/literal.rb', line 192
def ==(other)
eq(other).to_bool
end
|
#_perform(environment) ⇒ Literal (protected)
Evaluates the literal.
235 236 237 |
# File 'lib/sass/script/literal.rb', line 235
def _perform(environment)
self
end
|
#assert_int!
203 |
# File 'lib/sass/script/literal.rb', line 203
def assert_int!; to_i; end
|
#children ⇒ Array<Node>
Returns an empty array.
34 35 36 |
# File 'lib/sass/script/literal.rb', line 34
def children
[]
end
|
#comma(other) ⇒ Script::String
The SassScript ,
operation (e.g. $a, $b
, "foo", "bar"
).
107 108 109 |
# File 'lib/sass/script/literal.rb', line 107
def comma(other)
Sass::Script::String.new("#{self.to_s},#{' ' unless options[:style] == :compressed}#{other.to_s}")
end
|
#deep_copy
39 40 41 |
# File 'lib/sass/script/literal.rb', line 39
def deep_copy
dup
end
|
#div(other) ⇒ Script::String
The SassScript /
operation.
147 148 149 |
# File 'lib/sass/script/literal.rb', line 147
def div(other)
Sass::Script::String.new("#{self.to_s}/#{other.to_s}")
end
|
#eq(other) ⇒ Bool
The SassScript ==
operation.
Note that this returns a Bool object,
not a Ruby boolean.
67 68 69 |
# File 'lib/sass/script/literal.rb', line 67
def eq(other)
Sass::Script::Bool.new(self.class == other.class && self.value == other.value)
end
|
#inspect ⇒ String
Returns A readable representation of the literal.
179 180 181 |
# File 'lib/sass/script/literal.rb', line 179
def inspect
value.inspect
end
|
#minus(other) ⇒ Script::String
The SassScript -
operation.
138 139 140 |
# File 'lib/sass/script/literal.rb', line 138
def minus(other)
Sass::Script::String.new("#{self.to_s}-#{other.to_s}")
end
|
#neq(other) ⇒ Bool
The SassScript !=
operation.
Note that this returns a Bool object,
not a Ruby boolean.
78 79 80 |
# File 'lib/sass/script/literal.rb', line 78
def neq(other)
Sass::Script::Bool.new(!eq(other).to_bool)
end
|
#null? ⇒ Boolean
Returns whether or not this object is null.
225 226 227 |
# File 'lib/sass/script/literal.rb', line 225
def null?
false
end
|
#options ⇒ {Symbol => Object}
Returns the options hash for this node.
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/sass/script/literal.rb', line 49
def options
opts = super
return opts if opts
raise Sass::SyntaxError.new(<<MSG)
The #options attribute is not set on this #{self.class}.
This error is probably occurring because #to_s was called
on this literal within a custom Sass function without first
setting the #option attribute.
MSG
end
|
#plus(other) ⇒ Script::String
The SassScript +
operation.
126 127 128 129 130 131 |
# File 'lib/sass/script/literal.rb', line 126
def plus(other)
if other.is_a?(Sass::Script::String)
return Sass::Script::String.new(self.to_s + other.value, other.type)
end
Sass::Script::String.new(self.to_s + other.to_s)
end
|
#single_eq(other) ⇒ Script::String
The SassScript =
operation
(used for proprietary MS syntax like alpha(opacity=20)
).
117 118 119 |
# File 'lib/sass/script/literal.rb', line 117
def single_eq(other)
Sass::Script::String.new("#{self.to_s}=#{other.to_s}")
end
|
#space(other) ⇒ Script::String
The SassScript default operation (e.g. $a $b
, "foo" "bar"
).
98 99 100 |
# File 'lib/sass/script/literal.rb', line 98
def space(other)
Sass::Script::String.new("#{self.to_s} #{other.to_s}")
end
|
#to_a ⇒ Array<Literal>
Returns the value of this literal as a list. Single literals are considered the same as single-element lists.
209 210 211 |
# File 'lib/sass/script/literal.rb', line 209
def to_a
[self]
end
|
#to_bool ⇒ Boolean
Returns true
(the Ruby boolean value).
184 185 186 |
# File 'lib/sass/script/literal.rb', line 184
def to_bool
true
end
|
#to_i ⇒ Fixnum
Returns The integer value of this literal.
198 199 200 |
# File 'lib/sass/script/literal.rb', line 198
def to_i
raise Sass::SyntaxError.new("#{self.inspect} is not an integer.")
end
|
#to_s(opts = {}) ⇒ String Also known as: to_sass
Returns the string representation of this literal as it would be output to the CSS document.
217 218 219 |
# File 'lib/sass/script/literal.rb', line 217
def to_s(opts = {})
raise Sass::SyntaxError.new("[BUG] All subclasses of Sass::Literal must implement #to_s.")
end
|
#unary_div ⇒ Script::String
The SassScript unary /
operation (e.g. /$a
).
174 175 176 |
# File 'lib/sass/script/literal.rb', line 174
def unary_div
Sass::Script::String.new("/#{self.to_s}")
end
|
#unary_minus ⇒ Script::String
The SassScript unary -
operation (e.g. -$a
).
165 166 167 |
# File 'lib/sass/script/literal.rb', line 165
def unary_minus
Sass::Script::String.new("-#{self.to_s}")
end
|
#unary_not ⇒ Bool
The SassScript ==
operation.
Note that this returns a Bool object,
not a Ruby boolean.
89 90 91 |
# File 'lib/sass/script/literal.rb', line 89
def unary_not
Sass::Script::Bool.new(!to_bool)
end
|
#unary_plus ⇒ Script::String
The SassScript unary +
operation (e.g. +$a
).
156 157 158 |
# File 'lib/sass/script/literal.rb', line 156
def unary_plus
Sass::Script::String.new("+#{self.to_s}")
end
|