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.
-
- (Script::String) comma(other)
The SassScript
,operation (e.g.$a, $b,"foo", "bar"). - - 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. - - ({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)). -
- (Script::String) space(other)
The SassScript default operation (e.g.
$a $b,"foo" "bar"). - - (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.
23 24 25 26 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 23
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.
18 19 20 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 18
def value
@value
end
|
Instance Method Details
- (Boolean) ==(other)
Compares this object with another.
191 192 193 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 191
def ==(other)
eq(other).to_bool
end
|
- (Literal) _perform(environment) (protected)
Evaluates the literal.
227 228 229 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 227
def _perform(environment)
self
end
|
- assert_int!
202 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 202
def assert_int!; to_i end
|
- (Array<Node>) children
Returns an empty array.
32 33 34 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 32
def children
[]
end
|
- (Script::String) comma(other)
The SassScript , operation (e.g. $a, $b, "foo", "bar").
106 107 108 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 106
def comma(other)
Sass::Script::String.new("#{self.to_s},#{' ' unless options[:style] == :compressed}#{other.to_s}")
end
|
- deep_copy
37 38 39 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 37
def deep_copy
dup
end
|
- (Script::String) div(other)
The SassScript / operation.
146 147 148 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 146
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.
66 67 68 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 66
def eq(other)
Sass::Script::Bool.new(self.class == other.class && self.value == other.value)
end
|
- (String) inspect
A readable representation of the literal
178 179 180 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 178
def inspect
value.inspect
end
|
- (Script::String) minus(other)
The SassScript - operation.
137 138 139 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 137
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.
77 78 79 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 77
def neq(other)
Sass::Script::Bool.new(!eq(other).to_bool)
end
|
- ({Symbol => Object}) options
Returns the options hash for this node.
47 48 49 50 51 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 47
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.
125 126 127 128 129 130 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 125
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)).
116 117 118 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 116
def single_eq(other)
Sass::Script::String.new("#{self.to_s}=#{other.to_s}")
end
|
- (Script::String) space(other)
The SassScript default operation (e.g. $a $b, "foo" "bar").
97 98 99 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 97
def space(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.
208 209 210 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 208
def to_a
[self]
end
|
- (Boolean) to_bool
true (the Ruby boolean value)
183 184 185 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 183
def to_bool
true
end
|
- (Fixnum) to_i
The integer value of this literal
197 198 199 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 197
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.
216 217 218 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 216
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).
173 174 175 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 173
def unary_div
Sass::Script::String.new("/#{self.to_s}")
end
|
- (Script::String) unary_minus
The SassScript unary - operation (e.g. -$a).
164 165 166 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 164
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.
88 89 90 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 88
def unary_not
Sass::Script::Bool.new(!to_bool)
end
|
- (Script::String) unary_plus
The SassScript unary + operation (e.g. +$a).
155 156 157 |
# File '/var/www/sass-pages/.sass/lib/sass/script/literal.rb', line 155
def unary_plus
Sass::Script::String.new("+#{self.to_s}")
end
|