Permalink
Browse files

Merge remote branch 'worldmaker/master'

Resolved conflicts for pretty much every file.
  • Loading branch information...
2 parents 5129131 + 66b86c6 commit cf81cfc9922c52af16059dbab3ee42884648a321 @lericson committed Jun 29, 2010
Showing with 93 additions and 6 deletions.
  1. +69 −0 README
  2. +23 −4 clevercss.py
  3. +1 −1 setup.py
  4. +0 −1 tests/__init__.py
View
@@ -0,0 +1,69 @@
+=========
+CleverCSS
+=========
+
+CleverCSS is a small markup language for CSS inspired by Python that can be used
+to build a style sheet in a clean and structured way. In many ways it's cleaner
+and more powerful than CSS2 is.
+
+The most obvious difference to CSS is the syntax: it is indentation based and
+not flat. While this is obviously against the Python Zen, it's nonetheless a
+good idea for structural styles.
+
+
+Nutshell
+========
+
+To get an idea of how CleverCSS works you can see a small example below. Note
+the indentation based syntax and how you can nest rules::
+
+ ul#comments, ol#comments:
+ margin: 0
+ padding: 0
+
+ li:
+ padding: 0.4em
+ margin: 0.8em 0 0.8em
+
+ h3:
+ font-size: 1.2em
+ p:
+ padding: 0.3em
+ p.meta:
+ text-align: right
+ color: #ddd
+
+Of course you can do the very same in CSS, but because of its flat nature the
+code would look more verbose. The following piece of code is the CleverCSS
+output of the above file::
+
+ ul#comments,
+ ol#comments {
+ margin: 0;
+ padding: 0;
+ }
+
+ ul#comments li,
+ ol#comments li {
+ padding: 0.4em;
+ margin: 0.8em 0 0.8em;
+ }
+
+ ul#comments li h3,
+ ol#comments li h3 {
+ font-size: 1.2em;
+ }
+
+ ul#comments li p,
+ ol#comments li p {
+ padding: 0.3em;
+ }
+
+ ul#comments li p.meta,
+ ol#comments li p.meta {
+ text-align: right;
+ color: #dddddd;
+ }
+
+But that's only a small example of what you can do with CleverCSS. Have a look
+at the following documentation of CleverCSS for more details.
View
@@ -421,6 +421,7 @@
_number_re = re.compile(_r_number + '(?![a-zA-Z0-9_])')
_value_re = re.compile(r'(%s)(%s)(?![a-zA-Z0-9_])' % (_r_number, '|'.join(_units)))
_color_re = re.compile(r'#' + ('[a-fA-f0-9]{1,2}' * 3))
+_backstring_re = re.compile(r'`([^`]*)`')
_string_re = re.compile('%s|([^\s*/();,.+$]+|\.(?!%s))+' % (_r_string, _r_call))
_url_re = re.compile(r'url\(\s*(%s|.*?)\s*\)' % _r_string)
_var_re = re.compile(r'(?<!\\)\$(?:([a-zA-Z_][a-zA-Z0-9_]*)|'
@@ -944,7 +945,7 @@ def brighten_color(color, context, amount=None):
return color
lightness *= 1.0 + amount.value / 100.0
else:
- raise EvalException(self.lineno, 'invalid unit %s for color '
+ raise EvalException(amount.lineno, 'invalid unit %s for color '
'calculations.' % amount.unit)
elif isinstance(amount, Number):
lightness += (amount.value / 100.0)
@@ -963,7 +964,7 @@ def darken_color(color, context, amount=None):
return color
lightness *= amount.value / 100.0
else:
- raise EvalException(self.lineno, 'invalid unit %s for color '
+ raise EvalException(amount.lineno, 'invalid unit %s for color '
'calculations.' % amount.unit)
elif isinstance(amount, Number):
lightness -= (amount.value / 100.0)
@@ -996,7 +997,7 @@ def __init__(self, value, lineno=None):
value = [int(value[i:i + 2], 16) for i in xrange(1, 7, 2)]
else:
raise ValueError()
- except ValueError, e:
+ except ValueError:
raise ParserError(lineno, 'invalid color value')
Literal.__init__(self, tuple(value), lineno)
@@ -1069,6 +1070,20 @@ def evaluate(self, context):
return Color(args, lineno=self.lineno)
+class Backstring(Literal):
+ """
+ A string meant to be escaped directly to output.
+ """
+ name = "backstring"
+
+ def __init__(self, nodes, lineno=None):
+ Expr.__init__(self, lineno)
+ self.nodes = nodes
+
+ def to_string(self, context):
+ return unicode(self.nodes)
+
+
class String(Literal):
name = 'string'
@@ -1091,7 +1106,7 @@ def mul(self, other, context):
class URL(Literal):
name = 'URL'
methods = {
- 'length': lambda x, c: Number(len(self.value))
+ 'length': lambda x, c: Number(len(x.value))
}
def add(self, other, context):
@@ -1378,6 +1393,7 @@ def process_string(m):
(_color_re, process('color')),
(_number_re, process('number')),
(_url_re, process('url', 1)),
+ (_backstring_re, process('backstring', 1)),
(_string_re, process_string),
(_var_re, lambda m: (m.group(1) or m.group(2), 'var')),
(_whitespace_re, None))
@@ -1485,6 +1501,9 @@ def primary(self, stream):
return RGB(tuple(args), lineno=stream.lineno)
else:
node = String('rgb')
+ elif token == 'backstring':
+ stream.next()
+ node = Backstring(value, lineno=stream.lineno)
elif token == 'string':
stream.next()
node = String(value, lineno=stream.lineno)
View
@@ -9,7 +9,7 @@
name='CleverCSS',
author='Armin Ronacher',
author_email='armin.ronacher@active-4.com',
- version='0.1',
+ version='0.1.5',
url='http://sandbox.pocoo.org/clevercss/',
py_modules=['clevercss'],
description='funky css preprocessor dammit',
View
@@ -159,7 +159,6 @@ def test_comments(self):
"""))
self.assertEqual("\n".join([s[1] for s in line_iter]),
"aa, bb:\n x:1")
-
if __name__ == '__main__':
main()

0 comments on commit cf81cfc

Please sign in to comment.