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.
Compares this object with another.
@param other [Object] The object to compare with @return [Boolean] Whether or not this literal is equivalent to `other`
# File lib/sass/script/literal.rb, line 204
204: def ==(other)
205: eq(other).to_bool
206: end
The SassScript `and` operation.
@param other [Literal] The right-hand side of the operator @return [Literal] The result of a logical and:
`other` if this literal isn't a false {Bool},
and this literal otherwise
# File lib/sass/script/literal.rb, line 58
58: def and(other)
59: to_bool ? other : self
60: end
@raise [Sass::SyntaxError] if this literal isn’t an integer
# File lib/sass/script/literal.rb, line 215
215: def assert_int!; to_i; end
Returns an empty array.
@return [Array
# File lib/sass/script/literal.rb, line 31
31: def children
32: []
33: end
The SassScript `,` operation (e.g. `$a, $b`, `“foo”, “bar”`).
@param other [Literal] The right-hand side of the operator @return [Script::String] A string containing both literals
separated by `", "`
# File lib/sass/script/literal.rb, line 119
119: def comma(other)
120: Sass::Script::String.new("#{self.to_s}, #{other.to_s}")
121: end
The SassScript default operation (e.g. `$a $b`, `“foo” “bar”`).
@param other [Literal] The right-hand side of the operator @return [Script::String] A string containing both literals
separated by a space
# File lib/sass/script/literal.rb, line 110
110: def concat(other)
111: Sass::Script::String.new("#{self.to_s} #{other.to_s}")
112: end
The SassScript `/` operation.
@param other [Literal] The right-hand side of the operator @return [Script::String] A string containing both literals
separated by `"/"`
# File lib/sass/script/literal.rb, line 159
159: def div(other)
160: Sass::Script::String.new("#{self.to_s}/#{other.to_s}")
161: end
The SassScript `==` operation. **Note that this returns a {Sass::Script::Bool} object, not a Ruby boolean**.
@param other [Literal] The right-hand side of the operator @return [Bool] True if this literal is the same as the other,
false otherwise
# File lib/sass/script/literal.rb, line 79
79: def eq(other)
80: Sass::Script::Bool.new(self.class == other.class && self.value == other.value)
81: end
@return [String] A readable representation of the literal
# File lib/sass/script/literal.rb, line 191
191: def inspect
192: value.inspect
193: end
The SassScript `-` operation.
@param other [Literal] The right-hand side of the operator @return [Script::String] A string containing both literals
separated by `"-"`
# File lib/sass/script/literal.rb, line 150
150: def minus(other)
151: Sass::Script::String.new("#{self.to_s}-#{other.to_s}")
152: end
The SassScript `!=` operation. **Note that this returns a {Sass::Script::Bool} object, not a Ruby boolean**.
@param other [Literal] The right-hand side of the operator @return [Bool] False if this literal is the same as the other,
true otherwise
# File lib/sass/script/literal.rb, line 90
90: def neq(other)
91: Sass::Script::Bool.new(!eq(other).to_bool)
92: end
Returns the options hash for this node.
@return [{Symbol => Object}] @raise [Sass::SyntaxError] if the options hash hasn’t been set.
This should only happen when the literal was created
outside of the parser and \{#to\_s} was called on it
# File lib/sass/script/literal.rb, line 41
41: def options
42: opts = super
43: return opts if opts
44: raise Sass::SyntaxError.new(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.)
45: end
The SassScript `or` operation.
@param other [Literal] The right-hand side of the operator @return [Literal] The result of the logical or:
this literal if it isn't a false {Bool},
and `other` otherwise
# File lib/sass/script/literal.rb, line 68
68: def or(other)
69: to_bool ? self : other
70: end
The SassScript `+` operation.
@param other [Literal] The right-hand side of the operator @return [Script::String] A string containing both literals
without any separation
# File lib/sass/script/literal.rb, line 138
138: def plus(other)
139: if other.is_a?(Sass::Script::String)
140: return Sass::Script::String.new(self.to_s + other.value, other.type)
141: end
142: Sass::Script::String.new(self.to_s + other.to_s)
143: end
The SassScript `=` operation (used for proprietary MS syntax like `alpha(opacity=20)`).
@param other [Literal] The right-hand side of the operator @return [Script::String] A string containing both literals
separated by `"="`
# File lib/sass/script/literal.rb, line 129
129: def single_eq(other)
130: Sass::Script::String.new("#{self.to_s}=#{other.to_s}")
131: end
@return [Boolean] `true` (the Ruby boolean value)
# File lib/sass/script/literal.rb, line 196
196: def to_bool
197: true
198: end
@return [Fixnum] The integer value of this literal @raise [Sass::SyntaxError] if this literal isn’t an integer
# File lib/sass/script/literal.rb, line 210
210: def to_i
211: raise Sass::SyntaxError.new("#{self.inspect} is not an integer.")
212: end
Returns the string representation of this literal as it would be output to the CSS document.
@return [String]
# File lib/sass/script/literal.rb, line 221
221: def to_s(opts = {})
222: raise Sass::SyntaxError.new("[BUG] All subclasses of Sass::Literal must implement #to_s.")
223: end
The SassScript unary `/` operation (e.g. `/$a`).
@param other [Literal] The right-hand side of the operator @return [Script::String] A string containing the literal
preceded by `"/"`
# File lib/sass/script/literal.rb, line 186
186: def unary_div
187: Sass::Script::String.new("/#{self.to_s}")
188: end
The SassScript unary `-` operation (e.g. `-$a`).
@param other [Literal] The right-hand side of the operator @return [Script::String] A string containing the literal
preceded by `"-"`
# File lib/sass/script/literal.rb, line 177
177: def unary_minus
178: Sass::Script::String.new("-#{self.to_s}")
179: end
The SassScript `==` operation. **Note that this returns a {Sass::Script::Bool} object, not a Ruby boolean**.
@param other [Literal] The right-hand side of the operator @return [Bool] True if this literal is the same as the other,
false otherwise
# File lib/sass/script/literal.rb, line 101
101: def unary_not
102: Sass::Script::Bool.new(!to_bool)
103: end
The SassScript unary `+` operation (e.g. `+$a`).
@param other [Literal] The right-hand side of the operator @return [Script::String] A string containing the literal
preceded by `"+"`
# File lib/sass/script/literal.rb, line 168
168: def unary_plus
169: Sass::Script::String.new("+#{self.to_s}")
170: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.