Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Supporting limited nested styles now, reintroduced element validation

  • Loading branch information...
commit 7c898549c25572443d98949afabddc273fb1ac0d 1 parent 1d65e8e
migurski migurski authored
Showing with 30 additions and 9 deletions.
  1. +4 −9 cascadenik/parse.py
  2. +3 −0  cascadenik/style.py
  3. +23 −0 nested-rules.py
13 cascadenik/parse.py
View
@@ -411,8 +411,8 @@ def parse_value(tokens):
# http://lesscss.org/#-nested-rules
#
print 4, selectors
- print parse_rule(chain([(tname, tvalue, line, col)], tokens), [], selectors, is_merc)
- raise Exception('wah')
+ ruleset += parse_rule(chain([(tname, tvalue, line, col)], tokens), [], selectors, is_merc)
+ print 'From parse_rule():', ruleset
elif tname in ('HASH', ) or (tname, tvalue) in [('CHAR', '.'), ('CHAR', '*'), ('CHAR', '['), ('CHAR', '&')]:
#
@@ -439,8 +439,6 @@ def parse_rule(tokens, neighbors, parents, is_merc):
#
def validate_selector_elements(elements, line, col):
- return # for now
-
if len(elements) > 2:
raise ParseException('Only two-element selectors are supported for Mapnik styles', line, col)
@@ -547,8 +545,6 @@ def validate_selector_elements(elements, line, col):
neighbors.append(Selector(*elements))
neighbors[-1].convertZoomTests(is_merc)
- print 'To parse_rule() again:', neighbors, parents, ElementClass
-
return parse_rule(tokens, neighbors, parents, is_merc)
elif (tname, tvalue) == ('CHAR', '{'):
@@ -580,10 +576,9 @@ class EmptySelector:
[selector.elements[-1].addName(name) for name in element.names]
[selector.elements[-1].addTest(test) for test in element.tests]
else:
- selector.elements.append(deepcopy(element))
+ selector.addElement(deepcopy(element))
+ validate_selector_elements(selector.elements, line, col)
selectors.append(selector)
- print 'To parse_block():', selectors
-
return parse_block(tokens, selectors, is_merc)
3  cascadenik/style.py
View
@@ -375,6 +375,9 @@ def __init__(self, *elements):
self.elements = elements[:]
+ def addElement(self, element):
+ self.elements = tuple(list(self.elements) + [element])
+
def convertZoomTests(self, is_merc):
""" Modify the tests on this selector to use mapnik-friendly
scale-denominator instead of shorthand zoom.
23 nested-rules.py
View
@@ -0,0 +1,23 @@
+from cascadenik.parse import stylesheet_declarations
+
+s = """
+ #roads,
+ #stuff
+ {
+ line-color: #f90;
+ line-width: 1;
+
+ &.more,
+ &.again
+ { line-width: 2; }
+
+ /*
+ name1,
+ name2
+ { line-width: 2; }
+ */
+ }
+"""
+
+for declaration in stylesheet_declarations(s):
+ print declaration
Please sign in to comment.
Something went wrong with that request. Please try again.