2008-10-12 23:26:56 -04:00
|
|
|
module Sass
|
|
|
|
module Script
|
2009-04-24 23:49:32 -04:00
|
|
|
# A SassScript parse node representing a variable.
|
2009-04-25 05:00:36 -04:00
|
|
|
class Variable < Node
|
2009-04-24 23:15:10 -04:00
|
|
|
# The name of the variable.
|
|
|
|
#
|
|
|
|
# @return [String]
|
2008-10-12 23:26:56 -04:00
|
|
|
attr_reader :name
|
|
|
|
|
2009-04-24 23:15:10 -04:00
|
|
|
# @param name [String] See \{#name}
|
2010-03-06 19:08:04 -05:00
|
|
|
def initialize(name)
|
2008-10-12 23:26:56 -04:00
|
|
|
@name = name
|
2010-03-25 20:19:50 -04:00
|
|
|
super()
|
2008-10-12 23:26:56 -04:00
|
|
|
end
|
|
|
|
|
2009-04-24 23:15:10 -04:00
|
|
|
# @return [String] A string representation of the variable
|
2010-04-03 17:43:12 -04:00
|
|
|
def inspect(opts = {})
|
2010-03-06 20:32:04 -05:00
|
|
|
return "!important" if name == "important"
|
2010-04-03 17:43:12 -04:00
|
|
|
"$#{dasherize(name, opts)}"
|
2008-10-12 23:26:56 -04:00
|
|
|
end
|
2010-01-26 21:43:24 -05:00
|
|
|
alias_method :to_sass, :inspect
|
2008-10-12 23:26:56 -04:00
|
|
|
|
2010-02-21 19:17:12 -05:00
|
|
|
# Returns an empty array.
|
|
|
|
#
|
|
|
|
# @return [Array<Node>] empty
|
|
|
|
# @see Node#children
|
|
|
|
def children
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
2009-04-24 23:15:10 -04:00
|
|
|
# Evaluates the variable.
|
|
|
|
#
|
|
|
|
# @param environment [Sass::Environment] The environment in which to evaluate the SassScript
|
|
|
|
# @return [Literal] The SassScript object that is the value of the variable
|
|
|
|
# @raise [Sass::SyntaxError] if the variable is undefined
|
2010-02-21 19:17:12 -05:00
|
|
|
def _perform(environment)
|
2010-03-27 05:29:42 -04:00
|
|
|
raise SyntaxError.new("Undefined variable: \"$#{name}\".") unless val = environment.var(name)
|
|
|
|
if val.is_a?(Number)
|
|
|
|
val = val.dup
|
|
|
|
val.original = nil
|
|
|
|
end
|
|
|
|
return val
|
2008-10-12 23:26:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|