Class: Sass::Environment
- Inherits:
-
Object
- Object
- Sass::Environment
- Defined in:
- /var/www/sass-pages/.sass/lib/sass/environment.rb
Overview
The lexical environment for SassScript. This keeps track of variable, mixin, and function 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
- - (Set<String>) files_in_use A set of names of files currently present in the stack.
- - (Sass::Callable) function(name) Gets a function from this Environment or one of its #parents.
- - (Environment) initialize(parent = nil) constructor A new instance of Environment.
- - (Sass::Callable) 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.
- - (Sass::Callable) set_function(name, value) Sets a function in this Environment or one of its #parents.
- - (Sass::Callable) set_local_function(name, value) Sets a function in this Environment.
- - (Sass::Callable) set_local_mixin(name, value) Sets a mixin in this Environment.
- - (Script::Literal) set_local_var(name, value) Sets a variable in this Environment.
- - (Sass::Callable) 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.
- - stack_trace
- - (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/sass-pages/.sass/lib/sass/environment.rb', line 24
def initialize(parent = nil)
@parent = parent
unless parent
@stack = []
@mixins_in_use = Set.new
@files_in_use = Set.new
end
end
|
Instance Attribute Details
- ({Symbol => Object}) options
The options hash. See the Sass options documentation.
37 38 39 |
# File '/var/www/sass-pages/.sass/lib/sass/environment.rb', line 37
def options
@options || parent_options || {}
end
|
- (Environment) parent (readonly)
The enclosing environment, or nil if this is the global environment.
20 21 22 |
# File '/var/www/sass-pages/.sass/lib/sass/environment.rb', line 20
def parent
@parent
end
|
Instance Method Details
- (Set<String>) files_in_use
A set of names of files currently present in the stack.
99 100 101 |
# File '/var/www/sass-pages/.sass/lib/sass/environment.rb', line 99
def files_in_use
@files_in_use ||= @parent.files_in_use
end
|
- (Sass::Callable) function(name)
Gets a function from this Environment or one of its #parents.
179 |
# File '/var/www/sass-pages/.sass/lib/sass/environment.rb', line 179
inherited_hash :function
|
- (Sass::Callable) mixin(name)
Gets a mixin from this Environment or one of its #parents.
176 |
# File '/var/www/sass-pages/.sass/lib/sass/environment.rb', line 176
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/sass-pages/.sass/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.
75 76 77 78 |
# File '/var/www/sass-pages/.sass/lib/sass/environment.rb', line 75
def pop_frame
pop_and_unuse if stack.last && stack.last[:prepared]
pop_and_unuse
end
|
- prepare_frame(frame_info)
Like #push_frame, but next time a stack frame is pushed, it will be merged with this frame.
70 71 72 |
# File '/var/www/sass-pages/.sass/lib/sass/environment.rb', line 70
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 64 |
# File '/var/www/sass-pages/.sass/lib/sass/environment.rb', line 55
def push_frame(frame_info)
top_of_stack = stack.last
if top_of_stack && top_of_stack.delete(:prepared)
top_of_stack.merge!(frame_info)
else
stack.push(top_of_stack = frame_info)
end
mixins_in_use << top_of_stack[:mixin] if top_of_stack[:mixin]
files_in_use << top_of_stack[:filename] if top_of_stack[:filename]
end
|
- (Sass::Callable) set_function(name, value)
Sets a function in this Environment or one of its #parents. If the function is already defined in some environment, that one is set; otherwise, a new one is created in this environment.
179 |
# File '/var/www/sass-pages/.sass/lib/sass/environment.rb', line 179
inherited_hash :function
|
- (Sass::Callable) set_local_function(name, value)
Sets a function in this Environment. Ignores any parent environments.
179 |
# File '/var/www/sass-pages/.sass/lib/sass/environment.rb', line 179
inherited_hash :function
|
- (Sass::Callable) set_local_mixin(name, value)
Sets a mixin in this Environment. Ignores any parent environments.
176 |
# File '/var/www/sass-pages/.sass/lib/sass/environment.rb', line 176
inherited_hash :mixin
|
- (Script::Literal) set_local_var(name, value)
Sets a variable in this Environment. Ignores any parent environments.
173 |
# File '/var/www/sass-pages/.sass/lib/sass/environment.rb', line 173
inherited_hash :var
|
- (Sass::Callable) 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.
176 |
# File '/var/www/sass-pages/.sass/lib/sass/environment.rb', line 176
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.
173 |
# File '/var/www/sass-pages/.sass/lib/sass/environment.rb', line 173
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/sass-pages/.sass/lib/sass/environment.rb', line 85
def stack
@stack ||= @parent.stack
end
|
- stack_trace
103 104 105 106 107 108 109 110 111 112 |
# File '/var/www/sass-pages/.sass/lib/sass/environment.rb', line 103
def stack_trace
trace = []
stack.reverse.each_with_index do |entry, i|
msg = "#{i == 0 ? "on" : "from"} line #{entry[:line]}"
msg << " of #{entry[:filename] || "an unknown file"}"
msg << ", in `#{entry[:mixin]}'" if entry[:mixin]
trace << msg
end
trace
end
|
- (Script::Literal) var(name)
Gets a variable from this Environment or one of its #parents.
173 |
# File '/var/www/sass-pages/.sass/lib/sass/environment.rb', line 173
inherited_hash :var
|