File: formatter.py

package info (click to toggle)
python-lesscpy 0.13.0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,428 kB
  • sloc: python: 3,572; sh: 5; makefile: 4
file content (45 lines) | stat: -rw-r--r-- 1,090 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# -*- coding: utf8 -*-
"""
.. module:: lesscpy.lessc.formatter
    :synopsis: CSS Formatter class.

    Copyright (c)
    See LICENSE for details.
.. moduleauthor:: Johann T. Mariusson <jtm@robot.is>
"""


class Formatter(object):

    def __init__(self, args):
        self.args = args

    def format(self, parse):
        """
        """
        if not parse.result:
            return ''
        eb = '\n'
        if self.args.xminify:
            eb = ''
            self.args.minify = True
        self.items = {}
        if self.args.minify:
            self.items.update({
                'nl': '',
                'tab': '',
                'ws': '',
                'eb': eb
            })
        else:
            tab = '\t' if self.args.tabs else ' ' * int(self.args.spaces)
            self.items.update({
                'nl': '\n',
                'tab': tab,
                'ws': ' ',
                'eb': eb
            })
        self.out = [u.fmt(self.items)
                    for u in parse.result
                    if u]
        return ''.join(self.out).strip()