summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerman M. Bravo <german.mb@deipi.com>2013-10-08 07:10:03 -0700
committerGerman M. Bravo <german.mb@deipi.com>2013-10-08 07:10:03 -0700
commit2ed59a71c6b696c379f8888be2c438041cdf2a0b (patch)
treeb88f0f0fde555b3c018e7b27c769cd9828435552
parent8763b22d75cabdd86437ebf2480ad844e71cba8a (diff)
downloadpyscss-2ed59a71c6b696c379f8888be2c438041cdf2a0b.tar.gz
Added support for @while
-rw-r--r--scss/__init__.py37
-rw-r--r--scss/tests/files/kronuz/while-test.css12
-rw-r--r--scss/tests/files/kronuz/while-test.scss11
3 files changed, 41 insertions, 19 deletions
diff --git a/scss/__init__.py b/scss/__init__.py
index c52fa98..f1fc6d6 100644
--- a/scss/__init__.py
+++ b/scss/__init__.py
@@ -574,8 +574,8 @@ class Scss(object):
self._do_for(rule, scope, block)
elif code == '@each':
self._do_each(rule, scope, block)
- # elif code == '@while':
- # self._do_while(rule, scope, block)
+ elif code == '@while':
+ self._do_while(rule, scope, block)
elif code in ('@variables', '@vars'):
self._get_variables(rule, scope, block)
elif block.unparsed_contents is None:
@@ -1133,23 +1133,22 @@ class Scss(object):
inner_rule.namespace.set_variable(var, value)
self.manage_children(inner_rule, scope)
- # @print_timing(10)
- # def _do_while(self, rule, scope, block):
- # THIS DOES NOT WORK AS MODIFICATION OF INNER VARIABLES ARE NOT KNOWN AT THIS POINT!!
- # """
- # Implements @while
- # """
- # first_val = None
- # while True:
- # val = self.calculator.calculate(block.argument, rule, rule.context, rule.options)
- # val = bool(False if not val or isinstance(val, six.string_types) and (val in ('0', 'false', 'undefined') or _variable_re.match(val)) else val)
- # if first_val is None:
- # first_val = val
- # if not val:
- # break
- # rule.unparsed_contents = block.unparsed_contents
- # self.manage_children(rule, scope)
- # rule.options['@if'] = first_val
+ @print_timing(10)
+ def _do_while(self, rule, scope, block):
+ """
+ Implements @while
+ """
+ calculator = Calculator(rule.namespace)
+ first_condition = condition = calculator.calculate(block.argument)
+ 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
+ # DEVIATION: Allow not creating a new namespace
+ inner_rule.namespace = rule.namespace
+ self.manage_children(inner_rule, scope)
+ condition = calculator.calculate(block.argument)
+ rule.options['@if'] = first_condition
@print_timing(10)
def _get_variables(self, rule, scope, block):
diff --git a/scss/tests/files/kronuz/while-test.css b/scss/tests/files/kronuz/while-test.css
new file mode 100644
index 0000000..f9d8e59
--- /dev/null
+++ b/scss/tests/files/kronuz/while-test.css
@@ -0,0 +1,12 @@
+.while-4 {
+ width: 24px;
+}
+.while-3 {
+ width: 23px;
+}
+.while-2 {
+ width: 22px;
+}
+.while-1 {
+ width: 21px;
+}
diff --git a/scss/tests/files/kronuz/while-test.scss b/scss/tests/files/kronuz/while-test.scss
new file mode 100644
index 0000000..72bb75f
--- /dev/null
+++ b/scss/tests/files/kronuz/while-test.scss
@@ -0,0 +1,11 @@
+@option style:legacy;
+
+$types: 4;
+$type-width: 20px;
+
+@while $types > 0 {
+ .while-#{$types} {
+ width: $type-width + $types;
+ }
+ $types: $types - 1;
+}