Class | Sass::Script::Literal |
In: |
lib/sass/script/literal.rb
|
Parent: | Node |
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.
value | [R] |
Returns the Ruby value of the literal. The type of this value varies based
on the subclass.
@return [Object] |
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 59 59: def and(other) 60: to_bool ? other : self 61: end
@raise [Sass::SyntaxError] if this literal isn‘t an integer
# File lib/sass/script/literal.rb, line 216 216: def assert_int!; to_i; end
Returns an empty array.
@return [Array<Node>] empty @see Node#children
# 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 120 120: def comma(other) 121: Sass::Script::String.new("#{self.to_s}, #{other.to_s}") 122: 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 111 111: def concat(other) 112: Sass::Script::String.new("#{self.to_s} #{other.to_s}") 113: 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 160 160: def div(other) 161: Sass::Script::String.new("#{self.to_s}/#{other.to_s}") 162: 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 80 80: def eq(other) 81: Sass::Script::Bool.new(self.class == other.class && self.value == other.value) 82: 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 151 151: def minus(other) 152: Sass::Script::String.new("#{self.to_s}-#{other.to_s}") 153: 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 91 91: def neq(other) 92: Sass::Script::Bool.new(!eq(other).to_bool) 93: 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}.\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") 45: 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 139 139: def plus(other) 140: if other.is_a?(Sass::Script::String) 141: return Sass::Script::String.new(self.to_s + other.value, other.type) 142: end 143: Sass::Script::String.new(self.to_s + other.to_s) 144: 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 130 130: def single_eq(other) 131: Sass::Script::String.new("#{self.to_s}=#{other.to_s}") 132: end
@return [Boolean] `true` (the Ruby boolean value)
# File lib/sass/script/literal.rb, line 197 197: def to_bool 198: true 199: 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 211 211: def to_i 212: raise Sass::SyntaxError.new("#{self.inspect} is not an integer.") 213: 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 187 187: def unary_div 188: Sass::Script::String.new("/#{self.to_s}") 189: 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 178 178: def unary_minus 179: Sass::Script::String.new("-#{self.to_s}") 180: 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 102 102: def unary_not 103: Sass::Script::Bool.new(!to_bool) 104: 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 169 169: def unary_plus 170: Sass::Script::String.new("+#{self.to_s}") 171: end
Evaluates the literal.
@param environment [Sass::Environment] The environment in which to evaluate the SassScript @return [Literal] This literal
# File lib/sass/script/literal.rb, line 233 233: def _perform(environment) 234: self 235: end