Class: Sass::BaseEnvironment
- Inherits:
-
Object
- Object
- Sass::BaseEnvironment
- Defined in:
- lib/sass/environment.rb
Overview
The abstract base class for lexical environments for SassScript.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#caller ⇒ Environment?
The environment of the caller of this environment's mixin or function.
-
#content ⇒ [Array<Sass::Tree::Node>, Environment]?
The content passed to this environment.
-
#deprecated_false_warning_given ⇒ Set<[String, int]>
readonly
Whether a warning has been emitted for misusing a deprecated false value.
-
#global_warning_given ⇒ Set<[String, String, int]>
readonly
Whether a warning has been emitted for assigning to the given global variable.
-
#options
readonly
The options passed to the Sass Engine.
-
#selector ⇒ Selector::CommaSequence?
The selector for the current CSS rule, or nil if there is no current CSS rule.
Class Method Summary collapse
-
.inherited_hash_accessor(name)
Note: when updating this, update sass/yard/inherited_hash.rb as well.
- .inherited_hash_reader(name)
- .inherited_hash_writer(name)
Instance Method Summary collapse
-
#global_env ⇒ Environment
The top-level Environment object.
-
#initialize(parent = nil, options = nil) ⇒ BaseEnvironment
constructor
A new instance of BaseEnvironment.
-
#stack ⇒ Sass::Stack
The import/mixin stack.
Constructor Details
#initialize(parent = nil, options = nil) ⇒ BaseEnvironment
Returns a new instance of BaseEnvironment.
95 96 97 98 99 100 101 |
# File 'lib/sass/environment.rb', line 95
def initialize(parent = nil, options = nil)
@parent = parent
@options = options || (parent && parent.options) || {}
@stack = Sass::Stack.new if @parent.nil?
@global_warning_given = Set.new
@deprecated_false_warning_given = Set.new
end
|
Instance Attribute Details
#caller ⇒ Environment?
The environment of the caller of this environment's mixin or function.
105 106 107 |
# File 'lib/sass/environment.rb', line 105
def caller
@caller || (@parent && @parent.caller)
end
|
#content ⇒ [Array<Sass::Tree::Node>, Environment]?
The content passed to this environment. This is naturally only set for mixin body environments with content passed in.
114 115 116 |
# File 'lib/sass/environment.rb', line 114
def content
@content || (@parent && @parent.content)
end
|
#deprecated_false_warning_given ⇒ Set<[String, int]> (readonly)
Whether a warning has been emitted for misusing a deprecated false value. This is a set of tuples containing the filename and its line number.
90 91 92 |
# File 'lib/sass/environment.rb', line 90
def deprecated_false_warning_given
@deprecated_false_warning_given
end
|
#global_warning_given ⇒ Set<[String, String, int]> (readonly)
Whether a warning has been emitted for assigning to the given global variable. This is a set of tuples containing the name of the variable, its filename, and its line number.
84 85 86 |
# File 'lib/sass/environment.rb', line 84
def global_warning_given
@global_warning_given
end
|
#options (readonly)
The options passed to the Sass Engine.
61 62 63 |
# File 'lib/sass/environment.rb', line 61
def options
@options
end
|
#selector ⇒ Selector::CommaSequence?
The selector for the current CSS rule, or nil if there is no current CSS rule.
123 124 125 |
# File 'lib/sass/environment.rb', line 123
def selector
@selector || (@caller && @caller.selector) || (@parent && @parent.selector)
end
|
Class Method Details
.inherited_hash_accessor(name)
Note: when updating this, update sass/yard/inherited_hash.rb as well.
9 10 11 12 |
# File '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 '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 |
# File '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.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
RUBY
end
|
Instance Method Details
#global_env ⇒ Environment
The top-level Environment object.
130 131 132 |
# File 'lib/sass/environment.rb', line 130
def global_env
@global_env ||= @parent.nil? ? self : @parent.global_env
end
|
#stack ⇒ Sass::Stack
The import/mixin stack.
137 138 139 |
# File 'lib/sass/environment.rb', line 137
def stack
@stack || global_env.stack
end
|