diff options
| author | German M. Bravo <german.mb@deipi.com> | 2013-10-05 11:54:18 -0500 |
|---|---|---|
| committer | German M. Bravo <german.mb@deipi.com> | 2013-10-05 11:54:18 -0500 |
| commit | 79b44c1ebeac2508c3c952dd5d2ba73450742cb7 (patch) | |
| tree | ac16e77eced54c2cf6666890e851c309c16a8c04 | |
| parent | aac6ceb28464c98199a0bd941e6db71724fd70ae (diff) | |
| download | pyscss-79b44c1ebeac2508c3c952dd5d2ba73450742cb7.tar.gz | |
Nesting style fixes
| -rw-r--r-- | scss/__init__.py | 31 | ||||
| -rw-r--r-- | scss/rule.py | 2 | ||||
| -rw-r--r-- | scss/tests/files/kronuz/style-nested.css | 15 | ||||
| -rw-r--r-- | scss/tests/files/kronuz/style-nested.scss | 29 |
4 files changed, 70 insertions, 7 deletions
diff --git a/scss/__init__.py b/scss/__init__.py index a159e25..5f194df 100644 --- a/scss/__init__.py +++ b/scss/__init__.py @@ -1491,16 +1491,33 @@ class Scss(object): result = '' dangling_property = False + separate = False + nesting = current_nesting = last_nesting = -1 if nst else 0 + nesting_stack = [] for rule in rules: + nested = rule.nested + if nested <= 1: + separate = True + + if nst: + last_nesting = current_nesting + current_nesting = nested + + delta_nesting = current_nesting - last_nesting + if delta_nesting > 0: + nesting_stack += [nesting] * delta_nesting + elif delta_nesting < 0: + nesting_stack = nesting_stack[:delta_nesting] + nesting = nesting_stack[-1] + if rule.is_empty: continue + if nst: + nesting += 1 + ancestry = rule.ancestry ancestry_len = len(ancestry) - nested = rule.nested - if nested < 0: - nested = 0 - nesting = nested if nst else 0 first_mismatch = 0 for i, (old_header, new_header) in enumerate(zip(prev_ancestry_headers, ancestry.headers)): @@ -1518,13 +1535,15 @@ class Scss(object): # Close blocks and outdent as necessary for i in range(len(prev_ancestry_headers), first_mismatch, -1): result += tb * (i - 1) + '}' + rnl - if nested == 0: - result += srnl # Open new blocks as necessary for i in range(first_mismatch, ancestry_len): header = ancestry.headers[i] + if separate: + if result: + result += srnl + separate = False if debug_info: if not rule.source_file.is_string: filename = rule.source_file.filename diff --git a/scss/rule.py b/scss/rule.py index fa28956..3601a12 100644 --- a/scss/rule.py +++ b/scss/rule.py @@ -239,7 +239,7 @@ class SassRule(object): namespace=None, lineno=0, extends_selectors=frozenset(), ancestry=None, - nested=-1): + nested=0): self.source_file = source_file self.import_key = import_key diff --git a/scss/tests/files/kronuz/style-nested.css b/scss/tests/files/kronuz/style-nested.css new file mode 100644 index 0000000..9b5eccc --- /dev/null +++ b/scss/tests/files/kronuz/style-nested.css @@ -0,0 +1,15 @@ +div.important { + background: orange; } + div.important a { + color: brown; + font-weight: bold; } +div.ok a { + color: green; } +div.err { + background: red; } + div.err a { + color: white; + font-weight: bold; } + +ul li { + color: black; } diff --git a/scss/tests/files/kronuz/style-nested.scss b/scss/tests/files/kronuz/style-nested.scss new file mode 100644 index 0000000..e3193f3 --- /dev/null +++ b/scss/tests/files/kronuz/style-nested.scss @@ -0,0 +1,29 @@ +@option style:nested; + +div { + &.important { + background: orange; + a { + color: brown; + font-weight: bold; + } + } + &.ok { + a { + color: green; + } + } + &.err { + background: red; + a { + color: white; + font-weight: bold; + } + } +} + +ul { + li { + color: black; + } +} |
