2012-03-30 19:32:11 +00:00
|
|
|
# -*- coding: utf8 -*-
|
2012-01-28 14:52:09 +00:00
|
|
|
"""
|
2012-03-30 19:32:11 +00:00
|
|
|
.. module:: lesscpy.lessc.formatter
|
|
|
|
:synopsis: CSS Formatter class.
|
2013-07-19 11:21:51 +02:00
|
|
|
|
2012-01-28 14:52:09 +00:00
|
|
|
Copyright (c)
|
|
|
|
See LICENSE for details.
|
2012-07-18 17:28:04 -04:00
|
|
|
.. moduleauthor:: Johann T. Mariusson <jtm@robot.is>
|
2012-01-28 14:52:09 +00:00
|
|
|
"""
|
2013-07-19 11:21:51 +02:00
|
|
|
|
|
|
|
|
2012-01-28 14:52:09 +00:00
|
|
|
class Formatter(object):
|
2013-07-19 11:21:51 +02:00
|
|
|
|
2012-03-25 13:58:38 +00:00
|
|
|
def __init__(self, args):
|
|
|
|
self.args = args
|
2013-07-19 11:21:51 +02:00
|
|
|
|
2012-03-25 13:58:38 +00:00
|
|
|
def format(self, parse):
|
2012-02-25 17:08:08 +00:00
|
|
|
"""
|
|
|
|
"""
|
2012-02-26 11:19:10 +00:00
|
|
|
if not parse.result:
|
|
|
|
return ''
|
2013-07-19 11:21:51 +02:00
|
|
|
eb = '\n'
|
2012-03-25 13:58:38 +00:00
|
|
|
if self.args.xminify:
|
2012-02-25 17:08:08 +00:00
|
|
|
eb = ''
|
2012-03-25 13:58:38 +00:00
|
|
|
self.args.minify = True
|
2012-02-25 17:08:08 +00:00
|
|
|
self.items = {}
|
2012-03-25 13:58:38 +00:00
|
|
|
if self.args.minify:
|
2012-02-25 17:08:08 +00:00
|
|
|
self.items.update({
|
|
|
|
'nl': '',
|
|
|
|
'tab': '',
|
|
|
|
'ws': '',
|
2012-02-26 10:59:21 +00:00
|
|
|
'eb': eb
|
2012-02-25 17:08:08 +00:00
|
|
|
})
|
|
|
|
else:
|
2012-03-25 13:58:38 +00:00
|
|
|
tab = '\t' if self.args.tabs else ' ' * int(self.args.spaces)
|
2012-02-25 17:08:08 +00:00
|
|
|
self.items.update({
|
|
|
|
'nl': '\n',
|
2012-03-25 13:58:38 +00:00
|
|
|
'tab': tab,
|
2012-02-25 17:08:08 +00:00
|
|
|
'ws': ' ',
|
2012-02-26 10:59:21 +00:00
|
|
|
'eb': eb
|
2012-02-25 17:08:08 +00:00
|
|
|
})
|
2013-07-19 11:21:51 +02:00
|
|
|
self.out = [u.fmt(self.items)
|
|
|
|
for u in parse.result
|
2012-02-25 17:08:08 +00:00
|
|
|
if u]
|
|
|
|
return ''.join(self.out).strip()
|