Class: Sass::ReadOnlyEnvironment

Inherits:
BaseEnvironment show all
Defined in:
/home/nweiz/code/sass-site/.sass/lib/sass/environment.rb

Overview

A read-only wrapper for a lexical environment for SassScript.

Instance Attribute Summary

Attributes inherited from BaseEnvironment

#options, #selector

Instance Method Summary (collapse)

Methods inherited from BaseEnvironment

#global?, #global_env, inherited_hash_accessor, inherited_hash_reader, inherited_hash_writer, #stack

Constructor Details

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

Returns a new instance of ReadOnlyEnvironment



178
179
180
181
# File '/home/nweiz/code/sass-site/.sass/lib/sass/environment.rb', line 178

def initialize(parent = nil, options = nil)
  super
  @content_cached = nil
end

Instance Method Details

- (ReadOnlyEnvironment) caller

The read-only environment of the caller of this environment's mixin or function.



186
187
188
189
190
# File '/home/nweiz/code/sass-site/.sass/lib/sass/environment.rb', line 186

def caller
  return @caller if @caller
  env = super
  @caller ||= env.is_a?(ReadOnlyEnvironment) ? env : ReadOnlyEnvironment.new(env, env.options)
end

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

The content passed to this environment. If the content's environment isn't already read-only, it's made read-only.

Returns:

  • ([Array<Sass::Tree::Node>, ReadOnlyEnvironment]?)

    The content nodes and the lexical environment of the content block. Returns nil when there is no content in this environment.

See Also:



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File '/home/nweiz/code/sass-site/.sass/lib/sass/environment.rb', line 200

def content
  # Return the cached content from a previous invocation if any
  return @content if @content_cached
  # get the content with a read-write environment from the superclass
  read_write_content = super
  if read_write_content
    tree, env = read_write_content
    # make the content's environment read-only
    if env && !env.is_a?(ReadOnlyEnvironment)
      env = ReadOnlyEnvironment.new(env, env.options)
    end
    @content_cached = true
    @content = [tree, env]
  else
    @content_cached = true
    @content = nil
  end
end