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.
-
#and(other) ⇒ Literal
The SassScript
and
operation. - #assert_int!
-
#children ⇒ Array<Node>
Returns an empty array.
-
#comma(other) ⇒ Script::String
The SassScript
,
operation (e.g.$a, $b
,"foo", "bar"
). -
#concat(other) ⇒ Script::String
The SassScript default operation (e.g.
$a $b
,"foo" "bar"
). -
#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. -
#options ⇒ {Symbol => Object}
Returns the options hash for this node.
-
#or(other) ⇒ Literal
The SassScript
or
operation. -
#plus(other) ⇒ Script::String
The SassScript
+
operation. -
#single_eq(other) ⇒ Script::String
The SassScript
=
operation (used for proprietary MS syntax likealpha(opacity=20)
). -
#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.
22 23 24 25 |
# File 'lib/sass/script/literal.rb', line 22
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.
17 18 19 |
# File 'lib/sass/script/literal.rb', line 17
def value
@value
end
|
Instance Method Details
#==(other) ⇒ Boolean
Compares this object with another.
204 205 206 |
# File 'lib/sass/script/literal.rb', line 204
def ==(other)
eq(other).to_bool
end
|
#_perform(environment) ⇒ Literal (protected)
Evaluates the literal.
232 233 234 |
# File 'lib/sass/script/literal.rb', line 232
def _perform(environment)
self
end
|
#and(other) ⇒ Literal
The SassScript and
operation.
58 59 60 |
# File 'lib/sass/script/literal.rb', line 58
def and(other)
to_bool ? other : self
end
|
#assert_int!
215 |
# File 'lib/sass/script/literal.rb', line 215
def assert_int!; to_i; end
|
#children ⇒ Array<Node>
Returns an empty array.
31 32 33 |
# File 'lib/sass/script/literal.rb', line 31
def children
[]
end
|
#comma(other) ⇒ Script::String
The SassScript ,
operation (e.g. $a, $b
, "foo", "bar"
).
119 120 121 |
# File 'lib/sass/script/literal.rb', line 119
def comma(other)
Sass::Script::String.new("#{self.to_s}, #{other.to_s}")
end
|
#concat(other) ⇒ Script::String
The SassScript default operation (e.g. $a $b
, "foo" "bar"
).
110 111 112 |
# File 'lib/sass/script/literal.rb', line 110
def concat(other)
Sass::Script::String.new("#{self.to_s} #{other.to_s}")
end
|
#div(other) ⇒ Script::String
The SassScript /
operation.
159 160 161 |
# File 'lib/sass/script/literal.rb', line 159
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.
79 80 81 |
# File 'lib/sass/script/literal.rb', line 79
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.
191 192 193 |
# File 'lib/sass/script/literal.rb', line 191
def inspect
value.inspect
end
|
#minus(other) ⇒ Script::String
The SassScript -
operation.
150 151 152 |
# File 'lib/sass/script/literal.rb', line 150
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.
90 91 92 |
# File 'lib/sass/script/literal.rb', line 90
def neq(other)
Sass::Script::Bool.new(!eq(other).to_bool)
end
|
#options ⇒ {Symbol => Object}
Returns the options hash for this node.
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/sass/script/literal.rb', line 41
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
|
#or(other) ⇒ Literal
The SassScript or
operation.
68 69 70 |
# File 'lib/sass/script/literal.rb', line 68
def or(other)
to_bool ? self : other
end
|
#plus(other) ⇒ Script::String
The SassScript +
operation.
138 139 140 141 142 143 |
# File 'lib/sass/script/literal.rb', line 138
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)
).
129 130 131 |
# File 'lib/sass/script/literal.rb', line 129
def single_eq(other)
Sass::Script::String.new("#{self.to_s}=#{other.to_s}")
end
|
#to_bool ⇒ Boolean
Returns true
(the Ruby boolean value).
196 197 198 |
# File 'lib/sass/script/literal.rb', line 196
def to_bool
true
end
|
#to_i ⇒ Fixnum
Returns The integer value of this literal.
210 211 212 |
# File 'lib/sass/script/literal.rb', line 210
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.
221 222 223 |
# File 'lib/sass/script/literal.rb', line 221
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
).
186 187 188 |
# File 'lib/sass/script/literal.rb', line 186
def unary_div
Sass::Script::String.new("/#{self.to_s}")
end
|
#unary_minus ⇒ Script::String
The SassScript unary -
operation (e.g. -$a
).
177 178 179 |
# File 'lib/sass/script/literal.rb', line 177
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.
101 102 103 |
# File 'lib/sass/script/literal.rb', line 101
def unary_not
Sass::Script::Bool.new(!to_bool)
end
|
#unary_plus ⇒ Script::String
The SassScript unary +
operation (e.g. +$a
).
168 169 170 |
# File 'lib/sass/script/literal.rb', line 168
def unary_plus
Sass::Script::String.new("+#{self.to_s}")
end
|