53 lines
1.6 KiB
Python
Raw Normal View History

2012-01-28 14:52:09 +00:00
"""
"""
2012-02-19 20:38:19 +00:00
from .node import Node
2012-02-25 17:08:08 +00:00
from lesscpy.lessc import utility
2012-02-19 20:38:19 +00:00
class Property(Node):
2012-02-25 17:08:08 +00:00
pass
2012-01-28 14:52:09 +00:00
def parse(self, scope):
2012-02-26 10:59:21 +00:00
if len(self.tokens) > 2:
property, style, _ = self.tokens
self.important = True
else:
property, style = self.tokens
self.important = False
2012-02-26 13:20:35 +00:00
self.property = ''.join(property)
2012-02-25 17:08:08 +00:00
self.parsed = []
if style:
2012-02-26 15:50:07 +00:00
self.parsed = self.process(style, scope)
# style = self.replace_variables(style, scope)
# style = self.preprocess(style)
# self.parsed = [p.parse(scope)
# if hasattr(p, 'parse')
# else p
# for p in style]
# self.parsed = [p for p in self.parsed if p]
2012-02-25 17:08:08 +00:00
return self
2012-02-26 11:19:10 +00:00
def preprocess(self, style):
"""
Hackish preprocessing from font shorthand tags.
"""
if self.property == 'font':
style = [''.join(u.expression())
if hasattr(u, 'expression')
else u
for u in style]
return style
2012-02-25 17:08:08 +00:00
def format(self, fills):
"""
"""
2012-02-26 10:59:21 +00:00
f = "%(tab)s%(property)s:%(ws)s%(style)s%(important)s;%(nl)s"
imp = ' !important' if self.important else ''
2012-02-25 17:08:08 +00:00
fills.update({
'property': self.property,
'style': ''.join([p.format(fills)
if hasattr(p, 'format')
2012-02-25 17:34:23 +00:00
else str(p)
2012-02-25 17:08:08 +00:00
for p in self.parsed]),
2012-02-26 10:59:21 +00:00
'important': imp
2012-02-25 17:08:08 +00:00
})
return f % fills