diff options
author | German M. Bravo <german.mb@deipi.com> | 2013-10-03 10:55:19 -0500 |
---|---|---|
committer | German M. Bravo <german.mb@deipi.com> | 2013-10-03 10:55:19 -0500 |
commit | 65f3c62c5e6a6bdded49128020ee83d2d2828fd2 (patch) | |
tree | 0e8651b98499fb0f1988930aefc0b92c0ed72100 /scss/rule.py | |
parent | e4f4910ce2ea86fad2268989f903ba448fb64bb3 (diff) | |
download | pyscss-65f3c62c5e6a6bdded49128020ee83d2d2828fd2.tar.gz |
Imports moved to the Namespace (options is shared among scopes and imports are not)
Diffstat (limited to 'scss/rule.py')
-rw-r--r-- | scss/rule.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/scss/rule.py b/scss/rule.py index 17cb2c5..7e531e2 100644 --- a/scss/rule.py +++ b/scss/rule.py @@ -97,6 +97,11 @@ class MixinScope(Scope): return "<%s(%s) at 0x%x>" % (self.__class__.__name__, ', '.join('[%s]' % ', '.join('%s:%s' % (f, n) for f, n in sorted(map.keys())) for map in self.maps), id(self)) +class ImportScope(Scope): + def __repr__(self): + return "<%s(%s) at 0x%x>" % (self.__class__.__name__, ', '.join('[%s]' % ', '.join(repr(k) for k in sorted(map.keys())) for map in self.maps), id(self)) + + class Namespace(object): """...""" _mutable = True @@ -118,6 +123,8 @@ class Namespace(object): self._mixins = MixinScope() + self._imports = ImportScope() + def _assert_mutable(self): if not self._mutable: raise AttributeError("This Namespace instance is immutable") @@ -129,12 +136,14 @@ class Namespace(object): self._variables = others[0]._variables.new_child() self._functions = others[0]._functions.new_child() self._mixins = others[0]._mixins.new_child() + self._imports = others[0]._imports.new_child() else: # Note that this will create a 2-dimensional scope where each of # these scopes is checked first in order. TODO is this right? self._variables = VariableScope(other._variables for other in others) self._functions = FunctionScope(other._functions for other in others) self._mixins = MixinScope(other._mixins for other in others) + self._imports = ImportScope(other._imports for other in others) return self def derive(self): @@ -155,6 +164,15 @@ class Namespace(object): raise TypeError("Expected a Sass type, while setting %s got %r" % (name, value,)) self._variables.set(name, value, force_local=local_only) + def has_import(self, name, path=None): + import_key = (name, path) + return import_key in self._imports + + def add_import(self, name, path=None): + self._assert_mutable() + import_key = (name, path) + self._imports[import_key] = True + def _get_callable(self, chainmap, name, arity): name = normalize_var(name) if arity is not None: |