Class: Sass::Tree::VariableNode

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

Overview

A dynamic node representing a variable definition.

See Also:

Constant Summary

Constants inherited from Node

Node::SAVED_OPTIONS

Instance Attribute Summary

Attributes inherited from Node

#children, #filename, #has_children, #line, #options

Instance Method Summary collapse

Methods inherited from Node

#<<, #==, #_around_dump, #_cssize, #_to_s, #balance, #check_child!, #children_to_src, #cssize, #cssize!, #dasherize, #do_extend, #each, #invalid_child?, #invisible?, #perform, #perform!, #perform_children, #run_interp, #selector_to_sass, #selector_to_scss, #selector_to_src, #semi, #style, #to_s, #to_sass, #to_scss

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) (protected)

Loads the new variable value into the environment.

Parameters:

  • environment (Sass::Environment)

    The lexical environment containing variable and mixin values



28
29
30
31
32
33
34
35
36
# File 'lib/sass/tree/variable_node.rb', line 28

def _perform(environment)
  return [] if @guarded && !environment.var(@name).nil?
  val = @expr.perform(environment)
  if @expr.context == :equals && val.is_a?(Sass::Script::String)
    val = Sass::Script::String.new(val.value)
  end
  environment.set_var(@name, val)
  []
end

#to_src(tabs, opts, fmt) (protected)

See Also:



20
21
22
# File 'lib/sass/tree/variable_node.rb', line 20

def to_src(tabs, opts, fmt)
  "#{'  ' * tabs}$#{dasherize(@name, opts)}: #{@expr.to_sass(opts)}#{' !default' if @guarded}#{semi fmt}\n"
end