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}.

Methods

Attributes

options  [W] 
parent  [R]  The enclosing environment, or nil if this is the global environment.

@return [Environment]

Public Class methods

@param parent [Environment] See \{parent}

[Source]

    # File lib/sass/environment.rb, line 22
22:     def initialize(parent = nil)
23:       @vars = {}
24:       @mixins = {}
25:       @parent = parent
26:       @stack = [] unless parent
27:       set_var("important", Script::String.new("!important")) unless @parent
28:     end

Public Instance methods

The options hash. See {file:SASS_REFERENCE.md#sass_options the Sass options documentation}.

@return [{Symbol => Object}]

[Source]

    # File lib/sass/environment.rb, line 34
34:     def options
35:       @options || (parent && parent.options) || {}
36:     end

Pop a stack frame from the mixin/include stack.

[Source]

    # File lib/sass/environment.rb, line 70
70:     def pop_frame
71:       stack.pop if stack.last[:prepared]
72:       stack.pop
73:     end

Like \{push_frame}, but next time a stack frame is pushed, it will be merged with this frame.

@param frame_info [{Symbol => Object}] Same as for \{push_frame}.

[Source]

    # File lib/sass/environment.rb, line 65
65:     def prepare_frame(frame_info)
66:       push_frame(frame_info.merge(:prepared => true))
67:     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.

[Source]

    # File lib/sass/environment.rb, line 52
52:     def push_frame(frame_info)
53:       if stack.last && stack.last[:prepared]
54:         stack.last.delete(:prepared)
55:         stack.last.merge!(frame_info)
56:       else
57:         stack.push(frame_info)
58:       end
59:     end

A list of stack frames in the mixin/include stack. The last element in the list is the most deeply-nested frame.

@return [Array<{Symbol => Object}>] The stack frames,

  of the form passed to \{#push\_frame}.

[Source]

    # File lib/sass/environment.rb, line 80
80:     def stack
81:       @stack ||= @parent.stack
82:     end

[Validate]