Class: Sass::Script::Literal

Inherits:
Node show all
Defined in:
/var/www/haml-pages/.haml/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.

Direct Known Subclasses

Bool, Color, Number, String

Instance Attribute Summary

Instance Method Summary

Methods inherited from Node

#dasherize, #perform

Constructor Details

- (Literal) initialize(value = nil)

Creates a new literal.

Parameters:

  • (Object) value (defaults to: nil) — The object for #value


22
23
24
25
# File '/var/www/haml-pages/.haml/lib/sass/script/literal.rb', line 22

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.

Returns:



17
18
19
# File '/var/www/haml-pages/.haml/lib/sass/script/literal.rb', line 17

def value
  @value
end

Instance Method Details

- (Boolean) ==(other)

Compares this object with another.

Parameters:

  • (Object) other — The object to compare with

Returns:

  • (Boolean) — Whether or not this literal is equivalent to other


205
206
207
# File '/var/www/haml-pages/.haml/lib/sass/script/literal.rb', line 205

def ==(other)
  eq(other).to_bool
end

- (Literal) _perform(environment) (protected)

Evaluates the literal.

Parameters:

  • (Sass::Environment) environment — The environment in which to evaluate the SassScript

Returns:



233
234
235
# File '/var/www/haml-pages/.haml/lib/sass/script/literal.rb', line 233

def _perform(environment)
  self
end

- (Literal) and(other)

The SassScript and operation.

Parameters:

  • (Literal) other — The right-hand side of the operator

Returns:

  • (Literal) — The result of a logical and: other if this literal isn’t a false Bool, and this literal otherwise


59
60
61
# File '/var/www/haml-pages/.haml/lib/sass/script/literal.rb', line 59

def and(other)
  to_bool ? other : self
end

- assert_int!

Raises:



216
# File '/var/www/haml-pages/.haml/lib/sass/script/literal.rb', line 216

def assert_int!; to_i end

- (Array<Node>) children

Returns an empty array.

Returns:

  • (Array<Node>) — empty

See Also:



31
32
33
# File '/var/www/haml-pages/.haml/lib/sass/script/literal.rb', line 31

def children
  []
end

- (Script::String) comma(other)

The SassScript , operation (e.g. $a, $b, "foo", "bar").

Parameters:

  • (Literal) other — The right-hand side of the operator

Returns:

  • (Script::String) — A string containing both literals separated by ", "


120
121
122
# File '/var/www/haml-pages/.haml/lib/sass/script/literal.rb', line 120

def comma(other)
  Sass::Script::String.new("#{self.to_s}, #{other.to_s}")
end

- (Script::String) concat(other)

The SassScript default operation (e.g. $a $b, "foo" "bar").

Parameters:

  • (Literal) other — The right-hand side of the operator

Returns:

  • (Script::String) — A string containing both literals separated by a space


111
112
113
# File '/var/www/haml-pages/.haml/lib/sass/script/literal.rb', line 111

def concat(other)
  Sass::Script::String.new("#{self.to_s} #{other.to_s}")
end

- (Script::String) div(other)

The SassScript / operation.

Parameters:

  • (Literal) other — The right-hand side of the operator

Returns:

  • (Script::String) — A string containing both literals separated by "/"


160
161
162
# File '/var/www/haml-pages/.haml/lib/sass/script/literal.rb', line 160

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.

Parameters:

  • (Literal) other — The right-hand side of the operator

Returns:

  • (Bool) — True if this literal is the same as the other, false otherwise


80
81
82
# File '/var/www/haml-pages/.haml/lib/sass/script/literal.rb', line 80

def eq(other)
  Sass::Script::Bool.new(self.class == other.class && self.value == other.value)
end

- (String) inspect

A readable representation of the literal

Returns:

  • (String) — A readable representation of the literal


192
193
194
# File '/var/www/haml-pages/.haml/lib/sass/script/literal.rb', line 192

def inspect
  value.inspect
end

- (Script::String) minus(other)

The SassScript - operation.

Parameters:

  • (Literal) other — The right-hand side of the operator

Returns:

  • (Script::String) — A string containing both literals separated by "-"


151
152
153
# File '/var/www/haml-pages/.haml/lib/sass/script/literal.rb', line 151

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.

Parameters:

  • (Literal) other — The right-hand side of the operator

Returns:

  • (Bool) — False if this literal is the same as the other, true otherwise


91
92
93
# File '/var/www/haml-pages/.haml/lib/sass/script/literal.rb', line 91

def neq(other)
  Sass::Script::Bool.new(!eq(other).to_bool)
end

- ({Symbol => Object}) options

Returns the options hash for this node.

Returns:

Raises:

  • (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


41
42
43
44
45
# File '/var/www/haml-pages/.haml/lib/sass/script/literal.rb', line 41

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

- (Literal) or(other)

The SassScript or operation.

Parameters:

  • (Literal) other — The right-hand side of the operator

Returns:

  • (Literal) — The result of the logical or: this literal if it isn’t a false Bool, and other otherwise


69
70
71
# File '/var/www/haml-pages/.haml/lib/sass/script/literal.rb', line 69

def or(other)
  to_bool ? self : other
end

- (Script::String) plus(other)

The SassScript + operation.

Parameters:

  • (Literal) other — The right-hand side of the operator

Returns:

  • (Script::String) — A string containing both literals without any separation


139
140
141
142
143
144
# File '/var/www/haml-pages/.haml/lib/sass/script/literal.rb', line 139

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)).

Parameters:

  • (Literal) other — The right-hand side of the operator

Returns:

  • (Script::String) — A string containing both literals separated by "="


130
131
132
# File '/var/www/haml-pages/.haml/lib/sass/script/literal.rb', line 130

def single_eq(other)
  Sass::Script::String.new("#{self.to_s}=#{other.to_s}")
end

- (Boolean) to_bool

true (the Ruby boolean value)

Returns:

  • (Boolean)true (the Ruby boolean value)


197
198
199
# File '/var/www/haml-pages/.haml/lib/sass/script/literal.rb', line 197

def to_bool
  true
end

- (Fixnum) to_i

The integer value of this literal

Returns:

  • (Fixnum) — The integer value of this literal

Raises:



211
212
213
# File '/var/www/haml-pages/.haml/lib/sass/script/literal.rb', line 211

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.

Returns:

Raises:



222
223
224
# File '/var/www/haml-pages/.haml/lib/sass/script/literal.rb', line 222

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).

Parameters:

  • (Literal) other — The right-hand side of the operator

Returns:

  • (Script::String) — A string containing the literal preceded by "/"


187
188
189
# File '/var/www/haml-pages/.haml/lib/sass/script/literal.rb', line 187

def unary_div
  Sass::Script::String.new("/#{self.to_s}")
end

- (Script::String) unary_minus

The SassScript unary - operation (e.g. -$a).

Parameters:

  • (Literal) other — The right-hand side of the operator

Returns:

  • (Script::String) — A string containing the literal preceded by "-"


178
179
180
# File '/var/www/haml-pages/.haml/lib/sass/script/literal.rb', line 178

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.

Parameters:

  • (Literal) other — The right-hand side of the operator

Returns:

  • (Bool) — True if this literal is the same as the other, false otherwise


102
103
104
# File '/var/www/haml-pages/.haml/lib/sass/script/literal.rb', line 102

def unary_not
  Sass::Script::Bool.new(!to_bool)
end

- (Script::String) unary_plus

The SassScript unary + operation (e.g. +$a).

Parameters:

  • (Literal) other — The right-hand side of the operator

Returns:

  • (Script::String) — A string containing the literal preceded by "+"


169
170
171
# File '/var/www/haml-pages/.haml/lib/sass/script/literal.rb', line 169

def unary_plus
  Sass::Script::String.new("+#{self.to_s}")
end