Class Index [+]

Quicksearch

Sass::Script::Literal

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.

Attributes

value[R]

Returns the Ruby value of the literal. The type of this value varies based on the subclass.

@return [Object]

Public Class Methods

new(value = nil) click to toggle source

Creates a new literal.

@param value [Object] The object for {#value}

    # File lib/sass/script/literal.rb, line 22
22:     def initialize(value = nil)
23:       @value = value
24:       super()
25:     end

Public Instance Methods

==(other) click to toggle source

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
and(other) click to toggle source

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
assert_int!() click to toggle source

@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
children() click to toggle source

Returns an empty array.

@return [Array] empty @see Node#children

    # File lib/sass/script/literal.rb, line 31
31:     def children
32:       []
33:     end
comma(other) click to toggle source

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
concat(other) click to toggle source

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
div(other) click to toggle source

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
eq(other) click to toggle source

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
inspect() click to toggle source

@return [String] A readable representation of the literal

     # File lib/sass/script/literal.rb, line 191
191:     def inspect
192:       value.inspect
193:     end
minus(other) click to toggle source

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
neq(other) click to toggle source

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
options() click to toggle source

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
or(other) click to toggle source

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
plus(other) click to toggle source

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
single_eq(other) click to toggle source

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
to_bool() click to toggle source

@return [Boolean] `true` (the Ruby boolean value)

     # File lib/sass/script/literal.rb, line 196
196:     def to_bool
197:       true
198:     end
to_i() click to toggle source

@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
to_s(opts = {}) click to toggle source

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
Also aliased as: to_sass
to_sass(opts = {}) click to toggle source
Alias for: to_s
unary_div() click to toggle source

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
unary_minus() click to toggle source

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
unary_not() click to toggle source

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
unary_plus() click to toggle source

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

Protected Instance Methods

_perform(environment) click to toggle source

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 232
232:     def _perform(environment)
233:       self
234:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.