/scalate-jruby/src/main/resources/haml-3.0.25/lib/sass/script/variable.rb

http://github.com/scalate/scalate · Ruby · 48 lines · 28 code · 5 blank · 15 comment · 3 complexity · 1faeb25d8a76943507fce2554bf115ac MD5 · raw file

  1. module Sass
  2. module Script
  3. # A SassScript parse node representing a variable.
  4. class Variable < Node
  5. # The name of the variable.
  6. #
  7. # @return [String]
  8. attr_reader :name
  9. # @param name [String] See \{#name}
  10. def initialize(name)
  11. @name = name
  12. super()
  13. end
  14. # @return [String] A string representation of the variable
  15. def inspect(opts = {})
  16. return "!important" if name == "important"
  17. "$#{dasherize(name, opts)}"
  18. end
  19. alias_method :to_sass, :inspect
  20. # Returns an empty array.
  21. #
  22. # @return [Array<Node>] empty
  23. # @see Node#children
  24. def children
  25. []
  26. end
  27. protected
  28. # Evaluates the variable.
  29. #
  30. # @param environment [Sass::Environment] The environment in which to evaluate the SassScript
  31. # @return [Literal] The SassScript object that is the value of the variable
  32. # @raise [Sass::SyntaxError] if the variable is undefined
  33. def _perform(environment)
  34. raise SyntaxError.new("Undefined variable: \"$#{name}\".") unless val = environment.var(name)
  35. if val.is_a?(Number)
  36. val = val.dup
  37. val.original = nil
  38. end
  39. return val
  40. end
  41. end
  42. end
  43. end