Class: Sass::Script::Literal
- Inherits:
-
Node
- Object
- Node
- Sass::Script::Literal
- Defined in:
- /var/www/sass-pages/.sass/lib/sass/script/literal.rb
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.
- - assert_int!
- - (Array<Node>) children Returns an empty array.
- - deep_copy
-
- (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. - - (Boolean) null? Returns whether or not this object is null.
- - ({Symbol => Object}) options Returns the options hash for this node.
-
- (Script::String) plus(other)
The SassScript
+operation. -
- (Script::String) single_eq(other)
The SassScript
=operation (used for proprietary MS syntax likealpha(opacity=20)). - - (Array<Literal>) to_a Returns the value of this literal as a list.
-
- (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.
25 26 27 28 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 25
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.
20 21 22 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 20
def value
@value
end
|
Instance Method Details
- (Boolean) ==(other)
Compares this object with another.
175 176 177 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 175
def ==(other)
eq(other).to_bool
end
|
- (Literal) _perform(environment) (protected)
Evaluates the literal.
218 219 220 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 218
def _perform(environment)
self
end
|
- assert_int!
186 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 186
def assert_int!; to_i end
|
- (Array<Node>) children
Returns an empty array.
34 35 36 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 34
def children
[]
end
|
- deep_copy
39 40 41 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 39
def deep_copy
dup
end
|
- (Script::String) div(other)
The SassScript / operation.
130 131 132 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 130
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.
68 69 70 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 68
def eq(other)
Sass::Script::Bool.new(self.class == other.class && self.value == other.value)
end
|
- (String) inspect
A readable representation of the literal
162 163 164 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 162
def inspect
value.inspect
end
|
- (Script::String) minus(other)
The SassScript - operation.
121 122 123 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 121
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.
79 80 81 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 79
def neq(other)
Sass::Script::Bool.new(!eq(other).to_bool)
end
|
- (Boolean) null?
Returns whether or not this object is null.
208 209 210 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 208
def null?
false
end
|
- ({Symbol => Object}) options
Returns the options hash for this node.
49 50 51 52 53 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 49
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
|
- (Script::String) plus(other)
The SassScript + operation.
109 110 111 112 113 114 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 109
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)).
100 101 102 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 100
def single_eq(other)
Sass::Script::String.new("#{self.to_s}=#{other.to_s}")
end
|
- (Array<Literal>) to_a
Returns the value of this literal as a list. Single literals are considered the same as single-element lists.
192 193 194 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 192
def to_a
[self]
end
|
- (Boolean) to_bool
true (the Ruby boolean value)
167 168 169 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 167
def to_bool
true
end
|
- (Fixnum) to_i
The integer value of this literal
181 182 183 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 181
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.
200 201 202 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 200
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).
157 158 159 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 157
def unary_div
Sass::Script::String.new("/#{self.to_s}")
end
|
- (Script::String) unary_minus
The SassScript unary - operation (e.g. -$a).
148 149 150 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 148
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.
90 91 92 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 90
def unary_not
Sass::Script::Bool.new(!to_bool)
end
|
- (Script::String) unary_plus
The SassScript unary + operation (e.g. +$a).
139 140 141 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 139
def unary_plus
Sass::Script::String.new("+#{self.to_s}")
end
|