Class: Sass::Tree::VariableNode

Inherits:
Node show all
Defined in:
lib/sass/tree/variable_node.rb

Overview

A dynamic node representing a variable definition.

See Also:

Instance Attribute Summary

Attributes inherited from Node

#children, #filename, #line, #options

Instance Method Summary collapse

Methods inherited from Node

#<<, #==, #_to_s, #balance, #interpolate, #invalid_child?, #invisible?, #last, #perform, #perform!, #perform_children, #render, #style, #to_s, #to_sass

Constructor Details

#initialize(name, expr, guarded) ⇒ VariableNode

Returns a new instance of VariableNode.

Parameters:

  • name (String)

    The name of the variable

  • expr (Script::Node)

    The parse tree for the initial variable value

  • guarded (Boolean)

    Whether this is a guarded variable assignment (||=)



10
11
12
13
14
15
# File 'lib/sass/tree/variable_node.rb', line 10

def initialize(name, expr, guarded)
  @name = name
  @expr = expr
  @guarded = guarded
  super()
end

Instance Method Details

#_perform(environment) ⇒ Object (protected)

Loads the new variable value into the environment.

Parameters:

  • environment (Sass::Environment)

    The lexical environment containing variable and mixin values



23
24
25
26
27
28
29
30
31
# File 'lib/sass/tree/variable_node.rb', line 23

def _perform(environment)
  if @guarded && environment.var(@name).nil?
    environment.set_var(@name, @expr.perform(environment))
  elsif !@guarded
    environment.set_var(@name, @expr.perform(environment))
  end

  []
end