1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00
haml--haml/lib/sass/tree/variable_node.rb

44 lines
1.2 KiB
Ruby

module Sass
module Tree
# A dynamic node representing a variable definition.
#
# @see Sass::Tree
class VariableNode < Node
# @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 (`||=`)
def initialize(name, expr, guarded)
@name = name
@expr = expr
@guarded = guarded
super()
end
# @overload to_sass(tabs, opts = {})
# @see Node#to_sass
def to_sass(tabs, opts = {}, semi = '')
"#{' ' * tabs}!#{@name} #{'||' if @guarded}= #{@expr.to_sass}\n"
end
def to_scss(tabs, opts = {})
to_sass(tabs, opts, ';')
end
protected
# Loads the new variable value into the environment.
#
# @param environment [Sass::Environment] The lexical environment containing
# variable and mixin values
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
end
end
end