60 lines
1.8 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-27 19:10:22 +00:00
2012-02-19 20:38:19 +00:00
class Property(Node):
2012-01-28 14:52:09 +00:00
def parse(self, scope):
2012-02-26 16:36:13 +00:00
"""
"""
if not self.parsed:
if len(self.tokens) > 2:
property, style, _ = self.tokens
self.important = True
else:
property, style = self.tokens
self.important = False
self.property = ''.join(property)
self.parsed = []
if style:
style = self.preprocess(style)
self.parsed = self.process(style, scope)
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]
2012-02-27 19:10:22 +00:00
else:
style = [(u, ' ')
if hasattr(u, 'expression')
else u
for u in style]
2012-02-26 11:19:10 +00:00
return style
2012-02-25 17:08:08 +00:00
2012-03-03 09:58:47 +00:00
def fmt(self, fills):
2012-02-25 17:08:08 +00:00
"""
"""
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-26 16:36:13 +00:00
if fills['nl']:
self.parsed = [',%s' % fills['ws']
if p == ','
else p
for p in self.parsed]
2012-03-03 09:58:47 +00:00
style = ''.join([p.fmt(fills)
if hasattr(p, 'fmt')
2012-02-26 16:36:13 +00:00
else str(p)
for p in self.parsed])
2012-02-25 17:08:08 +00:00
fills.update({
'property': self.property,
2012-02-27 19:10:22 +00:00
'style': style.strip(),
2012-02-26 10:59:21 +00:00
'important': imp
2012-02-25 17:08:08 +00:00
})
return f % fills