Class: Sass::Script::Variable
Overview
A SassScript parse node representing a variable.
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
The name of the variable.
-
#underscored_name ⇒ String
readonly
The underscored 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.
- #deep_copy
-
#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.
16 17 18 19 20 |
# File 'lib/sass/script/variable.rb', line 16
def initialize(name)
@name = name
@underscored_name = name.gsub(/-/,"_")
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
|
#underscored_name ⇒ String (readonly)
The underscored name of the variable.
13 14 15 |
# File 'lib/sass/script/variable.rb', line 13
def underscored_name
@underscored_name
end
|
Instance Method Details
#_perform(environment) ⇒ Literal (protected)
Evaluates the variable.
48 49 50 51 52 53 54 55 |
# File 'lib/sass/script/variable.rb', line 48
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.
32 33 34 |
# File 'lib/sass/script/variable.rb', line 32
def children
[]
end
|
#deep_copy
37 38 39 |
# File 'lib/sass/script/variable.rb', line 37
def deep_copy
dup
end
|
#inspect(opts = {}) ⇒ String Also known as: to_sass
Returns A string representation of the variable.
23 24 25 |
# File 'lib/sass/script/variable.rb', line 23
def inspect(opts = {})
"$#{dasherize(name, opts)}"
end
|