From 4cf4f6a7eacff9da3ba88b74560d2eb8e3bb852c Mon Sep 17 00:00:00 2001 From: "German M. Bravo" Date: Tue, 8 Oct 2013 11:22:05 -0700 Subject: Configuration variables as deault options used from the config module at run time. Also added comments and renamed legacy_scoping -> control_scoping --- scss/__init__.py | 26 +++++++---------------- scss/config.py | 24 +++++++++++++++------ scss/tests/files/kronuz/scope-loop-variables.scss | 2 +- scss/tests/files/kronuz/scoping-control.scss | 2 +- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/scss/__init__.py b/scss/__init__.py index 1da1bc6..3eeaaed 100644 --- a/scss/__init__.py +++ b/scss/__init__.py @@ -127,14 +127,6 @@ _default_scss_vars = { 'bgc:': String.unquoted('background-color:'), } -_default_scss_opts = { - 'verbosity': config.VERBOSITY, - 'style': config.STYLE, - 'legacy-scoping': False, -} - -_default_search_paths = ['.'] - ################################################################################ @@ -340,15 +332,13 @@ class Scss(object): if self._scss_vars is not None: self.scss_vars.update(self._scss_vars) - self.scss_opts = _default_scss_opts.copy() - if self._scss_opts is not None: - self.scss_opts.update(self._scss_opts) + self.scss_opts = self._scss_opts.copy() if self._scss_opts else {} self.root_namespace = Namespace(variables=self.scss_vars, functions=self._library) # Figure out search paths. Fall back from provided explicitly to # defined globally to just searching the current directory - self.search_paths = list(_default_search_paths) + self.search_paths = ['.'] if self._search_paths is not None: assert not isinstance(self._search_paths, six.string_types), \ "`search_paths` should be an iterable, not a string" @@ -539,9 +529,9 @@ class Scss(object): elif code == '@debug': setting = block.argument.strip() if setting.lower() in ('1', 'true', 't', 'yes', 'y', 'on'): - setting = 1 + setting = True elif setting.lower() in ('0', 'false', 'f', 'no', 'n', 'off', 'undefined'): - setting = 0 + setting = False config.DEBUG = setting log.info("Debug mode is %s", 'On' if config.DEBUG else 'Off') elif code == '@option': @@ -1033,7 +1023,7 @@ class Scss(object): if condition: inner_rule = rule.copy() inner_rule.unparsed_contents = block.unparsed_contents - if rule.options.get('legacy_scoping'): # TODO: name this option differently and maybe make this scoping mode for contol structures as the default as a default deviation + if not rule.options.get('control_scoping', config.CONTROL_SCOPING): # TODO: maybe make this scoping mode for contol structures as the default as a default deviation # DEVIATION: Allow not creating a new namespace inner_rule.namespace = rule.namespace self.manage_children(inner_rule, scope) @@ -1084,7 +1074,7 @@ class Scss(object): inner_rule = rule.copy() inner_rule.unparsed_contents = block.unparsed_contents - if rule.options.get('legacy_scoping'): # TODO: name this option differently and maybe make this scoping mode for contol structures as the default as a default deviation + if not rule.options.get('control_scoping', config.CONTROL_SCOPING): # TODO: maybe make this scoping mode for contol structures as the default as a default deviation # DEVIATION: Allow not creating a new namespace inner_rule.namespace = rule.namespace @@ -1111,7 +1101,7 @@ class Scss(object): inner_rule = rule.copy() inner_rule.unparsed_contents = block.unparsed_contents - if rule.options.get('legacy_scoping'): # TODO: name this option differently and maybe make this scoping mode for contol structures as the default as a default deviation + if not rule.options.get('control_scoping', config.CONTROL_SCOPING): # TODO: maybe make this scoping mode for contol structures as the default as a default deviation # DEVIATION: Allow not creating a new namespace inner_rule.namespace = rule.namespace @@ -1135,7 +1125,7 @@ class Scss(object): while condition: inner_rule = rule.copy() inner_rule.unparsed_contents = block.unparsed_contents - if rule.options.get('legacy_scoping'): # TODO: name this option differently and maybe make this scoping mode for contol structures as the default as a default deviation + if not rule.options.get('control_scoping', config.CONTROL_SCOPING): # TODO: maybe make this scoping mode for contol structures as the default as a default deviation # DEVIATION: Allow not creating a new namespace inner_rule.namespace = rule.namespace self.manage_children(inner_rule, scope) diff --git a/scss/config.py b/scss/config.py index b562fb8..7836b65 100644 --- a/scss/config.py +++ b/scss/config.py @@ -1,26 +1,36 @@ ################################################################################ # Configuration: +DEBUG = False +VERBOSITY = 1 import os PROJECT_ROOT = os.path.normpath(os.path.dirname(os.path.abspath(__file__))) + # Sass @import load_paths: LOAD_PATHS = os.path.join(PROJECT_ROOT, 'sass/frameworks') -# Assets path, where new sprite files are created: -STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static') + # Assets path, where new sprite files are created (defaults to STATIC_ROOT + '/assets'): ASSETS_ROOT = None # Cache files path, where cache files are saved (defaults to ASSETS_ROOT): CACHE_ROOT = None +# Assets path, where new sprite files are created: +STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static') +FONTS_ROOT = None # default: STATIC_ROOT +IMAGES_ROOT = None # default: STATIC_ROOT + # Urls for the static and assets: -STATIC_URL = 'static/' ASSETS_URL = 'static/assets/' -FONTS_ROOT = None # default: STATIC_ROOT +STATIC_URL = 'static/' FONTS_URL = None # default: STATIC_URL -IMAGES_ROOT = None # default: STATIC_ROOT IMAGES_URL = None # default: STATIC_URL -VERBOSITY = True + +# Rendering style. Available values are 'nested', 'expanded', 'compact', 'compressed' and 'legacy' (defaults to 'nested'): STYLE = 'nested' + +# Use a different scope inside control structures create a scope (defaults to create new scopes for control structures, same as Sass): +CONTROL_SCOPING = True + +# Throw fatal errors when finding undefined variables: FATAL_UNDEFINED = True -DEBUG = 0 SPRTE_MAP_DIRECTION = 'vertical' diff --git a/scss/tests/files/kronuz/scope-loop-variables.scss b/scss/tests/files/kronuz/scope-loop-variables.scss index f04ba62..fda1e83 100644 --- a/scss/tests/files/kronuz/scope-loop-variables.scss +++ b/scss/tests/files/kronuz/scope-loop-variables.scss @@ -1,5 +1,5 @@ @option style:legacy; -@option legacy-scoping: yes; +@option control-scoping:no; div { @each $some in red blue { diff --git a/scss/tests/files/kronuz/scoping-control.scss b/scss/tests/files/kronuz/scoping-control.scss index 44d11a9..87d0f2e 100644 --- a/scss/tests/files/kronuz/scoping-control.scss +++ b/scss/tests/files/kronuz/scoping-control.scss @@ -1,5 +1,5 @@ @option style:legacy; -@option legacy-scoping:yes; +@option control-scoping:no; div { $first: red; -- cgit v1.2.1