2008-10-15 01:21:12 -07:00
|
|
|
module Sass
|
|
|
|
module Tree
|
2009-04-25 14:47:38 -07:00
|
|
|
# A dynamic node representing a variable definition.
|
|
|
|
#
|
|
|
|
# @see Sass::Tree
|
2008-10-15 01:21:12 -07:00
|
|
|
class VariableNode < Node
|
2009-04-25 14:47:38 -07:00
|
|
|
# @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 (`||=`)
|
2009-04-21 19:25:18 -07:00
|
|
|
def initialize(name, expr, guarded)
|
2008-10-15 01:21:12 -07:00
|
|
|
@name = name
|
|
|
|
@expr = expr
|
|
|
|
@guarded = guarded
|
2009-04-21 19:25:18 -07:00
|
|
|
super()
|
2008-10-15 01:21:12 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
2009-04-25 14:47:38 -07:00
|
|
|
# Loads the new variable value into the environment.
|
|
|
|
#
|
|
|
|
# @param environment [Sass::Environment] The lexical environment containing
|
|
|
|
# variable and mixin values
|
2008-10-15 01:21:12 -07:00
|
|
|
def _perform(environment)
|
2008-10-15 20:00:28 -07:00
|
|
|
if @guarded && environment.var(@name).nil?
|
|
|
|
environment.set_var(@name, @expr.perform(environment))
|
|
|
|
elsif !@guarded
|
|
|
|
environment.set_var(@name, @expr.perform(environment))
|
2008-10-15 01:21:12 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|