| Class | Sass::Environment |
| In: |
lib/sass/environment.rb
|
| Parent: | Object |
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}.
| options | [W] | |
| parent | [R] |
The enclosing environment, or nil if this is the global environment.
@return [Environment] |
@param parent [Environment] See \{parent}
# File lib/sass/environment.rb, line 24
24: def initialize(parent = nil)
25: @vars = {}
26: @mixins = {}
27: @parent = parent
28: @stack = [] unless parent
29: @mixins_in_use = Set.new unless parent
30: set_var("important", Script::String.new("!important")) unless @parent
31: end
Note: when updating this, update haml/yard/inherited_hash.rb as well.
# File lib/sass/environment.rb, line 101
101: def inherited_hash(name)
102: class_eval " def \#{name}(name)\n _\#{name}(name.gsub('_', '-'))\n end\n\n def _\#{name}(name)\n @\#{name}s[name] || @parent && @parent._\#{name}(name)\n end\n protected :_\#{name}\n\n def set_\#{name}(name, value)\n name = name.gsub('_', '-')\n @\#{name}s[name] = value unless try_set_\#{name}(name, value)\n end\n\n def try_set_\#{name}(name, value)\n if @\#{name}s.include?(name)\n @\#{name}s[name] = value\n true\n elsif @parent\n @parent.try_set_\#{name}(name, value)\n else\n false\n end\n end\n protected :try_set_\#{name}\n\n def set_local_\#{name}(name, value)\n @\#{name}s[name.gsub('_', '-')] = value\n end\n", __FILE__, __LINE__ + 1
103: end
Push a new stack frame onto the mixin/include stack.
@param frame_info [{Symbol => Object}]
Frame information has the following keys:
`:filename`
: The name of the file in which the lexical scope changed.
`:mixin`
: The name of the mixin in which the lexical scope changed,
or `nil` if it wasn't within in a mixin.
`:line`
: The line of the file on which the lexical scope changed. Never nil.
# File lib/sass/environment.rb, line 55
55: def push_frame(frame_info)
56: if stack.last && stack.last[:prepared]
57: stack.last.delete(:prepared)
58: stack.last.merge!(frame_info)
59: else
60: stack.push(frame_info)
61: end
62: mixins_in_use << stack.last[:mixin] if stack.last[:mixin] && !stack.last[:prepared]
63: end