Class Sass::Tree::VariableNode
In: lib/sass/tree/variable_node.rb
Parent: Node

A dynamic node representing a variable definition.

@see Sass::Tree

Methods

_perform   new   to_src  

Public Class methods

@param name [String] The name of the variable @param expr [Script::Node] The parse tree for the initial variable value @param guarded [Boolean] Whether this is a guarded variable assignment (`||=`)

[Source]

    # File lib/sass/tree/variable_node.rb, line 10
10:       def initialize(name, expr, guarded)
11:         @name = name
12:         @expr = expr
13:         @guarded = guarded
14:         super()
15:       end

Protected Instance methods

Loads the new variable value into the environment.

@param environment [Sass::Environment] The lexical environment containing

  variable and mixin values

[Source]

    # File lib/sass/tree/variable_node.rb, line 28
28:       def _perform(environment)
29:         return [] if @guarded && !environment.var(@name).nil?
30:         val = @expr.perform(environment)
31:         if @expr.context == :equals && val.is_a?(Sass::Script::String)
32:           val = Sass::Script::String.new(val.value)
33:         end
34:         environment.set_var(@name, val)
35:         []
36:       end

@see Node#to_src

[Source]

    # File lib/sass/tree/variable_node.rb, line 20
20:       def to_src(tabs, opts, fmt)
21:         "#{'  ' * tabs}$#{dasherize(@name, opts)}: #{@expr.to_sass(opts)}#{' !default' if @guarded}#{semi fmt}\n"
22:       end

[Validate]