1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00
haml--haml/lib/sass/environment.rb
Nathan Weizenbaum fb228b21d6 Merge branch 'master' into yard
Conflicts:

	lib/sass/environment.rb
2009-04-27 13:33:52 -07:00

79 lines
2.2 KiB
Ruby

module Sass
# 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::Functions}.
class Environment
# The enclosing environment,
# or nil if this is the global environment.
#
# @return [Environment]
attr_reader :parent
# @param parent [Environment] See \{#parent}
# @param options [Hash<Symbol, Object>] An options hash;
# see [the Sass options documentation](../Sass.html#sass_options)
def initialize(parent = nil, options = nil)
@vars = {}
@mixins = {}
@parent = parent
@options = options
end
# The options hash.
# See [the Sass options documentation](../Sass.html#sass_options).
#
# @return [Hash<Symbol, Object>]
def options
@options || (parent && parent.options) || {}
end
class << self
private
# Note: when updating this,
# update haml/yard/inherited_hash.rb as well.
def inherited_hash(name)
class_eval <<RUBY, __FILE__, __LINE__ + 1
def #{name}(name)
@#{name}s[name] || @parent && @parent.#{name}(name)
end
def set_#{name}(name, value)
@#{name}s[name] = value unless try_set_#{name}(name, value)
end
def try_set_#{name}(name, value)
if @#{name}s.include?(name)
@#{name}s[name] = value
true
elsif @parent
@parent.try_set_#{name}(name, value)
else
false
end
end
protected :try_set_#{name}
def set_local_#{name}(name, value)
@#{name}s[name] = value
end
RUBY
end
end
# variable
# Script::Literal
inherited_hash :var
# mixin
# Engine::Mixin
inherited_hash :mixin
end
end