How to use the lesscpy.lessc.parser function in lesscpy

To help you get started, we’ve selected a few lesscpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lesscpy / lesscpy / test / core.py View on Github external
def do_case_expected(self):
        lessf, cssf, minf = args
        if os.path.exists(cssf):
            p = parser.LessParser()
            p.parse(filename=lessf)
            f = formatter.Formatter(Opt())
            pout = f.format(p).split('\n')
            pl = len(pout)
            i = 0
            with open(cssf) as cssf:
                for line in cssf.readlines():
                    if i >= pl:
                        self.fail("%s: result has less lines (%d < %d)" %
                                  (cssf, i, pl))
                    line = line.rstrip()
                    if not line:
                        continue
                    self.assertEqual(line, pout[i],
                                     '%s: Line %d' % (cssf, i + 1))
                    i += 1
github lesscpy / lesscpy / test / core.py View on Github external
self.fail("%s: result has less lines (%d < %d)" %
                                  (cssf, i, pl))
                    line = line.rstrip()
                    if not line:
                        continue
                    self.assertEqual(line, pout[i],
                                     '%s: Line %d' % (cssf, i + 1))
                    i += 1
            if pl > i and i:
                self.fail(
                    "%s: result has more lines (%d > %d)" % (cssf, i, pl))
        else:
            self.fail("%s not found..." % cssf)
        if minf:
            if os.path.exists(minf):
                p = parser.LessParser()
                opt = Opt()
                opt.minify = True
                p.parse(filename=lessf)
                f = formatter.Formatter(opt)
                mout = f.format(p).split('\n')
                ml = len(mout)
                i = 0
                with open(minf) as cssf:
                    for line in cssf.readlines():
                        if i >= ml:
                            self.fail("%s: result has less lines (%d < %d)" %
                                      (minf, i, ml))
                        self.assertEqual(line.rstrip(), mout[i],
                                         '%s: Line %d' % (minf, i + 1))
                        i += 1
                if ml > i and i:
github lesscpy / lesscpy / lesscpy / scripts / compiler.py View on Github external
scope = p.scope
                    else:
                        scope.update(p.scope)
                else:
                    sys.exit('included file `%s` not found ...' % u)
                sys.stdout.flush()
        p = None
        f = formatter.Formatter(args)
        if not os.path.exists(args.target):
            sys.exit("Target not found '%s' ..." % args.target)
        if os.path.isdir(args.target):
            ldirectory(args.target, args.out, args, scope)
            if args.dry_run:
                print('Dry run, nothing done.', file=sys.stderr)
        else:
            p = parser.LessParser(
                yacc_debug=(args.debug),
                lex_optimize=True,
                yacc_optimize=(not args.debug),
                scope=copy.deepcopy(scope),
                verbose=args.verbose)
            p.parse(filename=args.target, debuglevel=args.debug)
            if args.scopemap:
                args.no_css = True
                p.scopemap()
            if not args.no_css and p:
                out = f.format(p)
                if args.output:
                    if not args.dont_create_dirs and not os.path.exists(
                            os.path.dirname(args.output)):
                        try:
                            os.makedirs(os.path.dirname(args.output))
github patacrep / patanet / generator / management / static_storage.py View on Github external
def compile_less(filename_in, filename_out, dry_run=True):
    """Compile a less file to css and write it to a file"""
    p = parser.LessParser(yacc_debug=False,
                          lex_optimize=True,
                          yacc_optimize=True,
                          scope=None,
                          tabfile=None,
                          verbose=False)
    p.parse(filename=filename_in, debuglevel=0)
    args = FormatterArgs()
    f = formatter.Formatter(args)
    css = f.format(p)
    if not dry_run:
        with open(filename_out, 'w') as outfile:
            outfile.write(css)
github lesscpy / lesscpy / lesscpy / scripts / compiler.py View on Github external
print("Creating '%s'" % outpath, file=sys.stderr)
            if not args.dry_run:
                os.mkdir(outpath)
    less = glob.glob(os.path.join(inpath, '*.less'))
    f = formatter.Formatter(args)
    for lf in less:
        outf = os.path.splitext(os.path.basename(lf))
        minx = '.min' if args.min_ending else ''
        outf = "%s/%s%s.css" % (outpath, outf[0], minx)
        if not args.force and os.path.exists(outf):
            recompile = os.path.getmtime(outf) < os.path.getmtime(lf)
        else:
            recompile = True
        if recompile:
            print('%s -> %s' % (lf, outf))
            p = parser.LessParser(
                yacc_debug=(args.debug),
                lex_optimize=True,
                yacc_optimize=(not args.debug),
                scope=scope,
                tabfile=yacctab,
                verbose=args.verbose)
            p.parse(filename=lf, debuglevel=0)
            css = f.format(p)
            if not args.dry_run:
                with open(outf, 'w') as outfile:
                    outfile.write(css)
        elif args.verbose:
            print('skipping %s, not modified' % lf, file=sys.stderr)
        sys.stdout.flush()
    if args.recurse:
        [
github lesscpy / lesscpy / lesscpy / __init__.py View on Github external
def compile(file, minify=False, xminify=False, tabs=False, spaces=True):
    from .lessc import parser
    from .lessc import formatter

    class Opt(object):
        def __init__(self):
            self.minify = minify
            self.xminify = xminify
            self.tabs = tabs
            self.spaces = spaces

    p = parser.LessParser(fail_with_exc=True)
    opt = Opt()
    p.parse(file=file)
    f = formatter.Formatter(opt)
    return f.format(p)