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
- - (Object) value readonly Returns the Ruby value of the literal.
Instance Method Summary
- - (Boolean) =(other) Compares this object with another.
- - (Literal) _perform(environment) protected Evaluates the literal.
-
- (Literal) and(other)
The SassScript
andoperation. - - assert_int!
- - (Array<Node>) children Returns an empty array.
-
- (Script::String) comma(other)
The SassScript
,operation (e.g.$a, $b,"foo", "bar"). -
- (Script::String) concat(other)
The SassScript default operation (e.g.
$a $b,"foo" "bar"). -
- (Script::String) div(other)
The SassScript
/operation. -
- (Bool) eq(other)
The SassScript
==operation. - - (Literal) initialize(value = nil) constructor Creates a new literal.
- - (String) inspect A readable representation of the literal.
-
- (Script::String) minus(other)
The SassScript
-operation. -
- (Bool) neq(other)
The SassScript
!=operation. - - ({Symbol => Object}) options Returns the options hash for this node.
-
- (Literal) or(other)
The SassScript
oroperation. -
- (Script::String) plus(other)
The SassScript
+operation. -
- (Script::String) single_eq(other)
The SassScript
=operation (used for proprietary MS syntax likealpha(opacity=20)). -
- (Boolean) to_bool
true(the Ruby boolean value). - - (Fixnum) to_i The integer value of this literal.
- - (String) to_s(opts = {}) (also: #to_sass) Returns the string representation of this literal as it would be output to the CSS document.
-
- (Script::String) unary_div
The SassScript unary
/operation (e.g./$a). -
- (Script::String) unary_minus
The SassScript unary
-operation (e.g.-$a). -
- (Bool) unary_not
The SassScript
==operation. -
- (Script::String) unary_plus
The SassScript unary
+operation (e.g.+$a).
Methods inherited from Node
Constructor Details
- (Literal) initialize(value = nil)
Creates a new literal.
22 23 24 25 |
# File '/var/www/sass-pages/.haml/lib/sass/script/literal.rb', line 22
def initialize(value = nil)
@value = value
super()
end
|
Instance Attribute Details
- (Object) value (readonly)
Returns the Ruby value of the literal. The type of this value varies based on the subclass.
17 18 19 |
# File '/var/www/sass-pages/.haml/lib/sass/script/literal.rb', line 17
def value
@value
end
|
Instance Method Details
- (Boolean) ==(other)
Compares this object with another.
205 206 207 |
# File '/var/www/sass-pages/.haml/lib/sass/script/literal.rb', line 205
def ==(other)
eq(other).to_bool
end
|
- (Literal) _perform(environment) (protected)
Evaluates the literal.
233 234 235 |
# File '/var/www/sass-pages/.haml/lib/sass/script/literal.rb', line 233
def _perform(environment)
self
end
|
- (Literal) and(other)
The SassScript and operation.
59 60 61 |
# File '/var/www/sass-pages/.haml/lib/sass/script/literal.rb', line 59
def and(other)
to_bool ? other : self
end
|
- assert_int!
216 |
# File '/var/www/sass-pages/.haml/lib/sass/script/literal.rb', line 216
def assert_int!; to_i end
|
- (Array<Node>) children
Returns an empty array.
31 32 33 |
# File '/var/www/sass-pages/.haml/lib/sass/script/literal.rb', line 31
def children
[]
end
|
- (Script::String) comma(other)
The SassScript , operation (e.g. $a, $b, "foo", "bar").
120 121 122 |
# File '/var/www/sass-pages/.haml/lib/sass/script/literal.rb', line 120
def comma(other)
Sass::Script::String.new("#{self.to_s}, #{other.to_s}")
end
|
- (Script::String) concat(other)
The SassScript default operation (e.g. $a $b, "foo" "bar").
111 112 113 |
# File '/var/www/sass-pages/.haml/lib/sass/script/literal.rb', line 111
def concat(other)
Sass::Script::String.new("#{self.to_s} #{other.to_s}")
end
|
- (Script::String) div(other)
The SassScript / operation.
160 161 162 |
# File '/var/www/sass-pages/.haml/lib/sass/script/literal.rb', line 160
def div(other)
Sass::Script::String.new("#{self.to_s}/#{other.to_s}")
end
|
- (Bool) eq(other)
The SassScript == operation. Note that this returns a Sass::Script::Bool object, not a Ruby boolean.
80 81 82 |
# File '/var/www/sass-pages/.haml/lib/sass/script/literal.rb', line 80
def eq(other)
Sass::Script::Bool.new(self.class == other.class && self.value == other.value)
end
|
- (String) inspect
A readable representation of the literal
192 193 194 |
# File '/var/www/sass-pages/.haml/lib/sass/script/literal.rb', line 192
def inspect
value.inspect
end
|
- (Script::String) minus(other)
The SassScript - operation.
151 152 153 |
# File '/var/www/sass-pages/.haml/lib/sass/script/literal.rb', line 151
def minus(other)
Sass::Script::String.new("#{self.to_s}-#{other.to_s}")
end
|
- (Bool) neq(other)
The SassScript != operation. Note that this returns a Sass::Script::Bool object, not a Ruby boolean.
91 92 93 |
# File '/var/www/sass-pages/.haml/lib/sass/script/literal.rb', line 91
def neq(other)
Sass::Script::Bool.new(!eq(other).to_bool)
end
|
- ({Symbol => Object}) options
Returns the options hash for this node.
41 42 43 44 45 |
# File '/var/www/sass-pages/.haml/lib/sass/script/literal.rb', line 41
def options
opts = super
return opts if opts
raise Sass::SyntaxError.new("The #options attribute is not set on this \#{self.class}.\n This error is probably occurring because #to_s was called\n on this literal within a custom Sass function without first\n setting the #option attribute.\n")
end
|
- (Literal) or(other)
The SassScript or operation.
69 70 71 |
# File '/var/www/sass-pages/.haml/lib/sass/script/literal.rb', line 69
def or(other)
to_bool ? self : other
end
|
- (Script::String) plus(other)
The SassScript + operation.
139 140 141 142 143 144 |
# File '/var/www/sass-pages/.haml/lib/sass/script/literal.rb', line 139
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
|
- (Script::String) single_eq(other)
The SassScript = operation (used for proprietary MS syntax like alpha(opacity=20)).
130 131 132 |
# File '/var/www/sass-pages/.haml/lib/sass/script/literal.rb', line 130
def single_eq(other)
Sass::Script::String.new("#{self.to_s}=#{other.to_s}")
end
|
- (Boolean) to_bool
true (the Ruby boolean value)
197 198 199 |
# File '/var/www/sass-pages/.haml/lib/sass/script/literal.rb', line 197
def to_bool
true
end
|
- (Fixnum) to_i
The integer value of this literal
211 212 213 |
# File '/var/www/sass-pages/.haml/lib/sass/script/literal.rb', line 211
def to_i
raise Sass::SyntaxError.new("#{self.inspect} is not an integer.")
end
|
- (String) to_s(opts = {}) Also known as: to_sass
Returns the string representation of this literal as it would be output to the CSS document.
222 223 224 |
# File '/var/www/sass-pages/.haml/lib/sass/script/literal.rb', line 222
def to_s(opts = {})
raise Sass::SyntaxError.new("[BUG] All subclasses of Sass::Literal must implement #to_s.")
end
|
- (Script::String) unary_div
The SassScript unary / operation (e.g. /$a).
187 188 189 |
# File '/var/www/sass-pages/.haml/lib/sass/script/literal.rb', line 187
def unary_div
Sass::Script::String.new("/#{self.to_s}")
end
|
- (Script::String) unary_minus
The SassScript unary - operation (e.g. -$a).
178 179 180 |
# File '/var/www/sass-pages/.haml/lib/sass/script/literal.rb', line 178
def unary_minus
Sass::Script::String.new("-#{self.to_s}")
end
|
- (Bool) unary_not
The SassScript == operation. Note that this returns a Sass::Script::Bool object, not a Ruby boolean.
102 103 104 |
# File '/var/www/sass-pages/.haml/lib/sass/script/literal.rb', line 102
def unary_not
Sass::Script::Bool.new(!to_bool)
end
|
- (Script::String) unary_plus
The SassScript unary + operation (e.g. +$a).
169 170 171 |
# File '/var/www/sass-pages/.haml/lib/sass/script/literal.rb', line 169
def unary_plus
Sass::Script::String.new("+#{self.to_s}")
end
|