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.
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 210 def ==(other) eq(other).to_bool 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 64 def and(other) to_bool ? other : self end
@raise [Sass::SyntaxError] if this literal isn't an integer
# File lib/sass/script/literal.rb, line 221 def assert_int!; to_i; end
Returns an empty array.
@return [Array<Node>] empty @see Node#children
# File lib/sass/script/literal.rb, line 32 def children [] 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 125 def comma(other) Sass::Script::String.new("#{self.to_s},#{' ' unless options[:style] == :compressed}#{other.to_s}") end
@see Node#deep_copy
# File lib/sass/script/literal.rb, line 37 def deep_copy dup 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 165 def div(other) Sass::Script::String.new("#{self.to_s}/#{other.to_s}") 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 85 def eq(other) Sass::Script::Bool.new(self.class == other.class && self.value == other.value) end
@return [String] A readable representation of the literal
# File lib/sass/script/literal.rb, line 197 def inspect value.inspect 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 156 def minus(other) Sass::Script::String.new("#{self.to_s}-#{other.to_s}") 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 96 def neq(other) Sass::Script::Bool.new(!eq(other).to_bool) 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 47 def options opts = super return opts if opts 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.) 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 74 def or(other) to_bool ? self : other 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 144 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
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 135 def single_eq(other) Sass::Script::String.new("#{self.to_s}=#{other.to_s}") 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 116 def space(other) Sass::Script::String.new("#{self.to_s} #{other.to_s}") end
Returns the value of this literal as a list. Single literals are considered the same as single-element lists.
@return [Array<Literal>] The of this literal as a list
# File lib/sass/script/literal.rb, line 227 def to_a [self] end
@return [Boolean] `true` (the Ruby boolean value)
# File lib/sass/script/literal.rb, line 202 def to_bool true 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 216 def to_i raise Sass::SyntaxError.new("#{self.inspect} is not an integer.") 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 235 def to_s(opts = {}) raise Sass::SyntaxError.new("[BUG] All subclasses of Sass::Literal must implement #to_s.") 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 192 def unary_div Sass::Script::String.new("/#{self.to_s}") 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 183 def unary_minus Sass::Script::String.new("-#{self.to_s}") 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 107 def unary_not Sass::Script::Bool.new(!to_bool) 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 174 def unary_plus Sass::Script::String.new("+#{self.to_s}") end
Generated with the Darkfish Rdoc Generator 2.