Class: Sass::BaseEnvironment

Inherits:
Object
  • Object
show all
Defined in:
/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/environment.rb

Overview

The abstract base class for lexical environments for SassScript.

Direct Known Subclasses

Environment, ReadOnlyEnvironment

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (BaseEnvironment) initialize(parent = nil, options = nil)

Returns a new instance of BaseEnvironment

Parameters:



86
87
88
89
90
91
92
93
94
95
96
97
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/environment.rb', line 86

def initialize(parent = nil, options = nil)
  @parent = parent
  @options = options || (parent && parent.options) || {}
  @stack = @parent.nil? ? Sass::Stack.new : nil
  @caller = nil
  @content = nil
  @filename = nil
  @functions = nil
  @mixins = nil
  @selector = nil
  @vars = nil
end

Instance Attribute Details

- (Environment?) caller

The environment of the caller of this environment’s mixin or function.

Returns:



108
109
110
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/environment.rb', line 108

def caller
  @caller || (@parent && @parent.caller)
end

- ([Array<Sass::Tree::Node>, Environment]?) content

The content passed to this environment. This is naturally only set for mixin body environments with content passed in.

Returns:



117
118
119
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/environment.rb', line 117

def content
  @content || (@parent && @parent.content)
end

- options (readonly)

The options passed to the Sass Engine.



65
66
67
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/environment.rb', line 65

def options
  @options
end

- (Selector::CommaSequence?) selector

The selector for the current CSS rule, or nil if there is no current CSS rule.

Returns:



126
127
128
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/environment.rb', line 126

def selector
  @selector || (@caller && @caller.selector) || (@parent && @parent.selector)
end

Class Method Details

+ inherited_hash_accessor(name)

update sass/yard/inherited_hash.rb as well.



9
10
11
12
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/environment.rb', line 9

def inherited_hash_accessor(name)
  inherited_hash_reader(name)
  inherited_hash_writer(name)
end

+ inherited_hash_reader(name)



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/environment.rb', line 14

def inherited_hash_reader(name)
  class_eval <<-RUBY, __FILE__, __LINE__ + 1
    def #{name}(name)
      _#{name}(name.tr('_', '-'))
    end

    def _#{name}(name)
      (@#{name}s && @#{name}s[name]) || @parent && @parent._#{name}(name)
    end
    protected :_#{name}

    def is_#{name}_global?(name)
      return !@parent if @#{name}s && @#{name}s.has_key?(name)
      @parent && @parent.is_#{name}_global?(name)
    end
  RUBY
end

+ inherited_hash_writer(name)



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/environment.rb', line 32

def inherited_hash_writer(name)
  class_eval <<-RUBY, __FILE__, __LINE__ + 1
    def set_#{name}(name, value)
      name = name.tr('_', '-')
      @#{name}s[name] = value unless try_set_#{name}(name, value)
    end

    def try_set_#{name}(name, value)
      @#{name}s ||= {}
      if @#{name}s.include?(name)
        @#{name}s[name] = value
        true
      elsif @parent && !@parent.global?
        @parent.try_set_#{name}(name, value)
      else
        false
      end
    end
    protected :try_set_#{name}

    def set_local_#{name}(name, value)
      @#{name}s ||= {}
      @#{name}s[name.tr('_', '-')] = value
    end

    def set_global_#{name}(name, value)
      global_env.set_#{name}(name, value)
    end
  RUBY
end

Instance Method Details

- (Boolean) global?

Returns whether this is the global environment.

Returns:

  • (Boolean)


102
103
104
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/environment.rb', line 102

def global?
  @parent.nil?
end

- (Environment) global_env

The top-level Environment object.

Returns:



133
134
135
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/environment.rb', line 133

def global_env
  @global_env ||= global? ? self : @parent.global_env
end

- (Sass::Stack) stack

The import/mixin stack.

Returns:



140
141
142
# File '/Users/ceppstei/Projects/sass-lang/.sass/lib/sass/environment.rb', line 140

def stack
  @stack || global_env.stack
end