class Sass::Environment

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

Constants

DASH

Attributes

options[W]
parent[R]

The enclosing environment, or nil if this is the global environment.

@return [Environment]

Public Class Methods

new(parent = nil) click to toggle source

@param parent [Environment] See {#parent}

# File 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

Public Instance Methods

files_in_use() click to toggle source

A set of names of files currently present in the stack.

@return [Set<String>] The filenames.

# File lib/sass/environment.rb, line 99
def files_in_use
  @files_in_use ||= @parent.files_in_use
end
mixins_in_use() click to toggle source

A set of names of mixins currently present in the stack.

@return [Set<String>] The mixin names.

# File lib/sass/environment.rb, line 92
def mixins_in_use
  @mixins_in_use ||= @parent.mixins_in_use
end
options() click to toggle source

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

@return [{Symbol => Object}]

# File lib/sass/environment.rb, line 37
def options
  @options || parent_options || {}
end
pop_frame() click to toggle source

Pop a stack frame from the mixin/include stack.

# File 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) click to toggle source

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

# File lib/sass/environment.rb, line 70
def prepare_frame(frame_info)
  push_frame(frame_info.merge(:prepared => true))
end
push_frame(frame_info) click to toggle source

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
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
stack() click to toggle source

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}.
# File lib/sass/environment.rb, line 85
def stack
  @stack ||= @parent.stack
end
stack_trace() click to toggle source
# File 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