Class: Sass::Environment
- Inherits:
-
Object
- Object
- Sass::Environment
- Defined in:
- /var/www/haml-pages/.haml/lib/sass/environment.rb
Overview
The lexical environment for SassScript. This keeps track of variable and mixin definitions.
A new environment is created for each level of Sass nesting. This allows variables to be lexically scoped. The new environment refers to the environment in the upper scope, so it has access to variables defined in enclosing scopes, but new variables are defined locally.
Environment also keeps track of the Engine options so that they can be made available to Sass::Script::Functions.
Instance Attribute Summary
- - ({Symbol => Object}) options The options hash.
- - (Environment) parent readonly The enclosing environment, or nil if this is the global environment.
Instance Method Summary
- - (Environment) initialize(parent = nil) constructor A new instance of Environment.
- - (Engine::Mixin) mixin(name) Gets a mixin from this Environment or one of its #parents.
- - (Set<String>) mixins_in_use A set of names of mixins currently present in the stack.
- - pop_frame Pop a stack frame from the mixin/include stack.
- - prepare_frame(frame_info) Like #push_frame, but next time a stack frame is pushed, it will be merged with this frame.
- - push_frame(frame_info) Push a new stack frame onto the mixin/include stack.
- - (Engine::Mixin) set_local_mixin(name, value) Sets a mixin in this Environment.
- - (Script::Literal) set_local_var(name, value) Sets a variable in this Environment.
- - (Engine::Mixin) set_mixin(name, value) Sets a mixin in this Environment or one of its #parents.
- - (Script::Literal) set_var(name, value) Sets a variable in this Environment or one of its #parents.
- - (Array<{Symbol => Object}>) stack A list of stack frames in the mixin/include stack.
- - (Script::Literal) var(name) Gets a variable from this Environment or one of its #parents.
Constructor Details
- (Environment) initialize(parent = nil)
A new instance of Environment
24 25 26 27 28 29 30 31 |
# File '/var/www/haml-pages/.haml/lib/sass/environment.rb', line 24
def initialize(parent = nil)
@vars = {}
@mixins = {}
@parent = parent
@stack = [] unless parent
@mixins_in_use = Set.new unless parent
set_var("important", Script::String.new("!important")) unless @parent
end
|
Instance Attribute Details
- ({Symbol => Object}) options
The options hash. See the Sass options documentation.
37 38 39 |
# File '/var/www/haml-pages/.haml/lib/sass/environment.rb', line 37
def options
@options || (parent && parent.options) || {}
end
|
- (Environment) parent (readonly)
The enclosing environment, or nil if this is the global environment.
20 21 22 |
# File '/var/www/haml-pages/.haml/lib/sass/environment.rb', line 20
def parent
@parent
end
|
Instance Method Details
- (Engine::Mixin) mixin(name)
Gets a mixin from this Environment or one of its #parents.
142 |
# File '/var/www/haml-pages/.haml/lib/sass/environment.rb', line 142
inherited_hash :mixin
|
- (Set<String>) mixins_in_use
A set of names of mixins currently present in the stack.
92 93 94 |
# File '/var/www/haml-pages/.haml/lib/sass/environment.rb', line 92
def mixins_in_use
@mixins_in_use ||= @parent.mixins_in_use
end
|
- pop_frame
Pop a stack frame from the mixin/include stack.
74 75 76 77 78 |
# File '/var/www/haml-pages/.haml/lib/sass/environment.rb', line 74
def pop_frame
stack.pop if stack.last && stack.last[:prepared]
popped = stack.pop
mixins_in_use.delete(popped[:mixin]) if popped && popped[:mixin]
end
|
- prepare_frame(frame_info)
Like #push_frame, but next time a stack frame is pushed, it will be merged with this frame.
69 70 71 |
# File '/var/www/haml-pages/.haml/lib/sass/environment.rb', line 69
def prepare_frame(frame_info)
push_frame(frame_info.merge(:prepared => true))
end
|
- push_frame(frame_info)
Push a new stack frame onto the mixin/include stack.
55 56 57 58 59 60 61 62 63 |
# File '/var/www/haml-pages/.haml/lib/sass/environment.rb', line 55
def push_frame(frame_info)
if stack.last && stack.last[:prepared]
stack.last.delete(:prepared)
stack.last.merge!(frame_info)
else
stack.push(frame_info)
end
mixins_in_use << stack.last[:mixin] if stack.last[:mixin] && !stack.last[:prepared]
end
|
- (Engine::Mixin) set_local_mixin(name, value)
Sets a mixin in this Environment. Ignores any parent environments.
142 |
# File '/var/www/haml-pages/.haml/lib/sass/environment.rb', line 142
inherited_hash :mixin
|
- (Script::Literal) set_local_var(name, value)
Sets a variable in this Environment. Ignores any parent environments.
139 |
# File '/var/www/haml-pages/.haml/lib/sass/environment.rb', line 139
inherited_hash :var
|
- (Engine::Mixin) set_mixin(name, value)
Sets a mixin in this Environment or one of its #parents. If the mixin is already defined in some environment, that one is set; otherwise, a new one is created in this environment.
142 |
# File '/var/www/haml-pages/.haml/lib/sass/environment.rb', line 142
inherited_hash :mixin
|
- (Script::Literal) set_var(name, value)
Sets a variable in this Environment or one of its #parents. If the variable is already defined in some environment, that one is set; otherwise, a new one is created in this environment.
139 |
# File '/var/www/haml-pages/.haml/lib/sass/environment.rb', line 139
inherited_hash :var
|
- (Array<{Symbol => Object}>) stack
A list of stack frames in the mixin/include stack. The last element in the list is the most deeply-nested frame.
85 86 87 |
# File '/var/www/haml-pages/.haml/lib/sass/environment.rb', line 85
def stack
@stack ||= @parent.stack
end
|
- (Script::Literal) var(name)
Gets a variable from this Environment or one of its #parents.
139 |
# File '/var/www/haml-pages/.haml/lib/sass/environment.rb', line 139
inherited_hash :var
|