/scalate-jruby/src/main/resources/haml-3.0.25/lib/sass/tree/variable_node.rb

http://github.com/scalate/scalate · Ruby · 39 lines · 25 code · 3 blank · 11 comment · 5 complexity · 876ae3e80947d4447326c136b568ea72 MD5 · raw file

  1. module Sass
  2. module Tree
  3. # A dynamic node representing a variable definition.
  4. #
  5. # @see Sass::Tree
  6. class VariableNode < Node
  7. # @param name [String] The name of the variable
  8. # @param expr [Script::Node] The parse tree for the initial variable value
  9. # @param guarded [Boolean] Whether this is a guarded variable assignment (`||=`)
  10. def initialize(name, expr, guarded)
  11. @name = name
  12. @expr = expr
  13. @guarded = guarded
  14. super()
  15. end
  16. protected
  17. # @see Node#to_src
  18. def to_src(tabs, opts, fmt)
  19. "#{' ' * tabs}$#{dasherize(@name, opts)}: #{@expr.to_sass(opts)}#{' !default' if @guarded}#{semi fmt}\n"
  20. end
  21. # Loads the new variable value into the environment.
  22. #
  23. # @param environment [Sass::Environment] The lexical environment containing
  24. # variable and mixin values
  25. def _perform(environment)
  26. return [] if @guarded && !environment.var(@name).nil?
  27. val = @expr.perform(environment)
  28. if @expr.context == :equals && val.is_a?(Sass::Script::String)
  29. val = Sass::Script::String.new(val.value)
  30. end
  31. environment.set_var(@name, val)
  32. []
  33. end
  34. end
  35. end
  36. end