Class Sass::Environment
In: lib/sass/environment.rb
Parent: Object
Haml::Util Engine Color SyntaxError UnitConversionError StandardError AbstractSequence CommaSequence Sequence SimpleSequence Simple Parent Universal Class SelectorPseudoClass Id Pseudo Attribute Interpolation Element Node Operation Literal UnaryOperation StringInterpolation Funcall Interpolation Variable Lexer CssLexer Number Bool String Parser Parser CssParser EvaluationContext StaticParser SassParser CssParser Node DebugNode IfNode CommentNode ForNode PropNode MixinNode DirectiveNode ExtendNode VariableNode WarnNode RootNode WhileNode RuleNode MixinDefNode Enumerable ImportNode Merb::BootLoader MerbBootLoader Repl CSS Environment Rack StalenessChecker lib/sass/repl.rb lib/sass/css.rb lib/sass/environment.rb lib/sass/error.rb lib/sass/engine.rb lib/sass/selector/simple_sequence.rb lib/sass/selector/abstract_sequence.rb lib/sass/selector/sequence.rb lib/sass/selector/comma_sequence.rb lib/sass/selector/simple.rb lib/sass/selector.rb Selector lib/sass/script/css_parser.rb lib/sass/script/lexer.rb lib/sass/script/color.rb lib/sass/script/string.rb lib/sass/script/unary_operation.rb lib/sass/script/variable.rb lib/sass/script/funcall.rb lib/sass/script/string_interpolation.rb lib/sass/script/operation.rb lib/sass/script/bool.rb lib/sass/script/parser.rb lib/sass/script/literal.rb lib/sass/script/node.rb lib/sass/script/interpolation.rb lib/sass/script/css_lexer.rb lib/sass/script/number.rb lib/sass/script/functions.rb Functions Script lib/sass/scss/sass_parser.rb lib/sass/scss/static_parser.rb lib/sass/scss/parser.rb lib/sass/scss/css_parser.rb ScriptLexer ScriptParser RX SCSS Files Callbacks lib/sass/tree/while_node.rb lib/sass/tree/if_node.rb lib/sass/tree/mixin_def_node.rb lib/sass/tree/debug_node.rb lib/sass/tree/root_node.rb lib/sass/tree/for_node.rb lib/sass/tree/import_node.rb lib/sass/tree/prop_node.rb lib/sass/tree/node.rb lib/sass/tree/comment_node.rb lib/sass/tree/extend_node.rb lib/sass/tree/mixin_node.rb lib/sass/tree/warn_node.rb lib/sass/tree/directive_node.rb lib/sass/tree/rule_node.rb lib/sass/tree/variable_node.rb Tree lib/sass/plugin/rack.rb lib/sass/plugin/staleness_checker.rb lib/sass/plugin/merb.rb Plugin Sass dot/m_85_0.png

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

Private Class methods

Note: when updating this, update haml/yard/inherited_hash.rb as well.

[Source]

     # 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

Public Instance methods

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

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

[Source]

    # File lib/sass/environment.rb, line 92
92:     def mixins_in_use
93:       @mixins_in_use ||= @parent.mixins_in_use
94:     end

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

@return [{Symbol => Object}]

[Source]

    # File lib/sass/environment.rb, line 37
37:     def options
38:       @options || (parent && parent.options) || {}
39:     end

Pop a stack frame from the mixin/include stack.

[Source]

    # File lib/sass/environment.rb, line 74
74:     def pop_frame
75:       stack.pop if stack.last && stack.last[:prepared]
76:       popped = stack.pop
77:       mixins_in_use.delete(popped[:mixin]) if popped && popped[:mixin]
78:     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 69
69:     def prepare_frame(frame_info)
70:       push_frame(frame_info.merge(:prepared => true))
71:     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 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

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 85
85:     def stack
86:       @stack ||= @parent.stack
87:     end

[Validate]