Class: Sass::Tree::VariableNode
- Defined in:
- lib/sass/tree/variable_node.rb
Overview
A dynamic node representing a variable definition.
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
#<<, #==, #_cssize, #_to_s, #balance, #children_to_src, #cssize, #cssize!, #dasherize, #each, #invalid_child?, #invisible?, #perform, #perform!, #perform_children, #render, #run_interp, #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.
27 28 29 30 31 32 33 34 35 |
# File 'lib/sass/tree/variable_node.rb', line 27
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)
19 20 21 |
# File 'lib/sass/tree/variable_node.rb', line 19
def to_src(tabs, opts, fmt)
"#{' ' * tabs}$#{dasherize(@name, opts)}: #{@expr.to_sass(opts)}#{' !default' if @guarded}#{semi fmt}\n"
end
|