Class: Sass::Script::Variable
Overview
A SassScript parse node representing a variable.
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
The name of the variable.
Attributes inherited from Node
Instance Method Summary collapse
-
#_perform(environment) ⇒ Literal
protected
Evaluates the variable.
-
#children ⇒ Array<Node>
Returns an empty array.
-
#initialize(name) ⇒ Variable
constructor
A new instance of Variable.
-
#inspect(opts = {}) ⇒ String
(also: #to_sass)
A string representation of the variable.
Methods inherited from Node
Constructor Details
#initialize(name) ⇒ Variable
Returns a new instance of Variable.
11 12 13 14 |
# File 'lib/sass/script/variable.rb', line 11
def initialize(name)
@name = name
super()
end
|
Instance Attribute Details
#name ⇒ String (readonly)
The name of the variable.
8 9 10 |
# File 'lib/sass/script/variable.rb', line 8
def name
@name
end
|
Instance Method Details
#_perform(environment) ⇒ Literal (protected)
Evaluates the variable.
38 39 40 41 42 43 44 45 |
# File 'lib/sass/script/variable.rb', line 38
def _perform(environment)
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
end
|
#children ⇒ Array<Node>
Returns an empty array.
27 28 29 |
# File 'lib/sass/script/variable.rb', line 27
def children
[]
end
|
#inspect(opts = {}) ⇒ String Also known as: to_sass
Returns A string representation of the variable.
17 18 19 20 |
# File 'lib/sass/script/variable.rb', line 17
def inspect(opts = {})
return "!important" if name == "important"
"$#{dasherize(name, opts)}"
end
|