Class: Sass::Script::Tree::Variable
- Defined in:
- lib/sass/script/tree/variable.rb
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
#filename, #line, #options, #source_range
Instance Method Summary collapse
-
#_perform(environment) ⇒ Sass::Script::Value
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
#dasherize, #force_division!, #opts, #perform
Constructor Details
#initialize(name) ⇒ Variable
Returns a new instance of Variable.
15 16 17 18 19 |
# File 'lib/sass/script/tree/variable.rb', line 15
def initialize(name)
@name = name
@underscored_name = name.tr("-", "_")
super()
end
|
Instance Attribute Details
#name ⇒ String (readonly)
The name of the variable.
7 8 9 |
# File 'lib/sass/script/tree/variable.rb', line 7
def name
@name
end
|
#underscored_name ⇒ String (readonly)
The underscored name of the variable.
12 13 14 |
# File 'lib/sass/script/tree/variable.rb', line 12
def underscored_name
@underscored_name
end
|
Instance Method Details
#_perform(environment) ⇒ Sass::Script::Value (protected)
Evaluates the variable.
47 48 49 50 51 52 53 54 55 |
# File 'lib/sass/script/tree/variable.rb', line 47
def _perform(environment)
val = environment.var(name)
raise Sass::SyntaxError.new("Undefined variable: \"$#{name}\".") unless val
if val.is_a?(Sass::Script::Value::Number) && val.original
val = val.dup
val.original = nil
end
val
end
|
#children ⇒ Array<Node>
Returns an empty array.
31 32 33 |
# File 'lib/sass/script/tree/variable.rb', line 31
def children
[]
end
|
#deep_copy
36 37 38 |
# File 'lib/sass/script/tree/variable.rb', line 36
def deep_copy
dup
end
|
#inspect(opts = {}) ⇒ String Also known as: to_sass
Returns A string representation of the variable.
22 23 24 |
# File 'lib/sass/script/tree/variable.rb', line 22
def inspect(opts = {})
"$#{dasherize(name, opts)}"
end
|