Class Sass::Script::Literal
In: lib/sass/script/literal.rb
Parent: Node
Haml::Util Engine Color SyntaxError UnitConversionError StandardError AbstractSequence CommaSequence Sequence SimpleSequence Simple Parent Universal Class SelectorPseudoClass Id Pseudo Attribute Interpolation Element Node Operation Literal UnaryOperation StringInterpolation Funcall Interpolation Variable Lexer CssLexer Number Bool String Parser Parser CssParser EvaluationContext SassParser StaticParser CssParser Node DebugNode IfNode CommentNode ForNode PropNode MixinNode DirectiveNode VariableNode RootNode ExtendNode WarnNode WhileNode RuleNode MixinDefNode Enumerable ImportNode Merb::BootLoader MerbBootLoader Repl CSS Environment Rack StalenessChecker lib/sass/repl.rb lib/sass/css.rb lib/sass/environment.rb lib/sass/error.rb lib/sass/engine.rb lib/sass/selector/simple_sequence.rb lib/sass/selector/abstract_sequence.rb lib/sass/selector/sequence.rb lib/sass/selector/comma_sequence.rb lib/sass/selector/simple.rb lib/sass/selector.rb Selector lib/sass/script/css_parser.rb lib/sass/script/lexer.rb lib/sass/script/color.rb lib/sass/script/string.rb lib/sass/script/unary_operation.rb lib/sass/script/variable.rb lib/sass/script/funcall.rb lib/sass/script/string_interpolation.rb lib/sass/script/operation.rb lib/sass/script/bool.rb lib/sass/script/parser.rb lib/sass/script/node.rb lib/sass/script/literal.rb lib/sass/script/interpolation.rb lib/sass/script/css_lexer.rb lib/sass/script/number.rb lib/sass/script/functions.rb Functions Script lib/sass/scss/sass_parser.rb lib/sass/scss/static_parser.rb lib/sass/scss/parser.rb lib/sass/scss/css_parser.rb ScriptLexer ScriptParser RX SCSS Files Callbacks lib/sass/tree/while_node.rb lib/sass/tree/if_node.rb lib/sass/tree/mixin_def_node.rb lib/sass/tree/debug_node.rb lib/sass/tree/root_node.rb lib/sass/tree/for_node.rb lib/sass/tree/import_node.rb lib/sass/tree/prop_node.rb lib/sass/tree/node.rb lib/sass/tree/comment_node.rb lib/sass/tree/extend_node.rb lib/sass/tree/mixin_node.rb lib/sass/tree/warn_node.rb lib/sass/tree/directive_node.rb lib/sass/tree/rule_node.rb lib/sass/tree/variable_node.rb Tree lib/sass/plugin/rack.rb lib/sass/plugin/staleness_checker.rb lib/sass/plugin/merb.rb Plugin Sass dot/m_63_0.png

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.

Methods

==   _perform   and   assert_int!   children   comma   concat   div   eq   inspect   minus   neq   new   options   or   plus   single_eq   to_bool   to_i   to_s   to_sass   unary_div   unary_minus   unary_not   unary_plus  

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

Creates a new literal.

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

[Source]

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

Public Instance methods

Compares this object with another.

@param other [Object] The object to compare with @return [Boolean] Whether or not this literal is equivalent to `other`

[Source]

     # File lib/sass/script/literal.rb, line 205
205:     def ==(other)
206:       eq(other).to_bool
207:     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

[Source]

    # 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

[Source]

     # 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

[Source]

    # 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 `", "`

[Source]

     # 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

[Source]

     # 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 `"/"`

[Source]

     # 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

[Source]

    # 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

@return [String] A readable representation of the literal

[Source]

     # File lib/sass/script/literal.rb, line 192
192:     def inspect
193:       value.inspect
194:     end

The SassScript `-` operation.

@param other [Literal] The right-hand side of the operator @return [Script::String] A string containing both literals

  separated by `"-"`

[Source]

     # 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

[Source]

    # 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

[Source]

    # 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 `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

[Source]

    # File lib/sass/script/literal.rb, line 69
69:     def or(other)
70:       to_bool ? self : other
71:     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

[Source]

     # 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 `"="`

[Source]

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

[Source]

     # 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

[Source]

     # 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

Returns the string representation of this literal as it would be output to the CSS document.

@return [String]

[Source]

     # File lib/sass/script/literal.rb, line 222
222:     def to_s(opts = {})
223:       raise Sass::SyntaxError.new("[BUG] All subclasses of Sass::Literal must implement #to_s.")
224:     end
to_sass(opts = {})

Alias for to_s

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 `"/"`

[Source]

     # 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 `"-"`

[Source]

     # 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

[Source]

     # 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 `"+"`

[Source]

     # File lib/sass/script/literal.rb, line 169
169:     def unary_plus
170:       Sass::Script::String.new("+#{self.to_s}")
171:     end

Protected Instance methods

Evaluates the literal.

@param environment [Sass::Environment] The environment in which to evaluate the SassScript @return [Literal] This literal

[Source]

     # File lib/sass/script/literal.rb, line 233
233:     def _perform(environment)
234:       self
235:     end

[Validate]