Class: Sass::Tree::VariableNode
- Defined in:
- lib/sass/tree/variable_node.rb
Overview
A dynamic node representing a variable definition.
Constant Summary
Constants inherited from Node
Instance Attribute Summary
Attributes inherited from Node
#children, #filename, #has_children, #line, #options
Instance Method Summary collapse
-
#_perform(environment)
protected
Loads the new variable value into the environment.
-
#initialize(name, expr, guarded) ⇒ VariableNode
constructor
A new instance of VariableNode.
- #to_src(tabs, opts, fmt) protected
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.
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.
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)
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
|