How to use the lesscpy.compile 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 / test_pycompile.py View on Github external
def fail_func():
            compile(StringIO("a }"), minify=True)
github lesscpy / lesscpy / test / test_pycompile.py View on Github external
def test_compile_from_file(self):
        """
        It can compile input from a file object
        """

        import tempfile
        in_file = tempfile.NamedTemporaryFile(mode='w+')
        in_file.write("a { border-width: 2px * 3; }")
        in_file.seek(0)
        output = compile(in_file, minify=True)
        self.assertEqual(output, "a{border-width:6px;}")
github krateng / maloja / maloja / server.py View on Github external
def generate_css():
	import lesscpy
	from io import StringIO
	less = ""
	for f in os.listdir(pthjoin(STATICFOLDER,"less")):
		with open(pthjoin(STATICFOLDER,"less",f),"r") as lessf:
			less += lessf.read()

	css = lesscpy.compile(StringIO(less),minify=True)
	return css
github mikeboers / PyHAML / haml / filters.py View on Github external
def less(src):
    import lesscpy
    return css(lesscpy.compile(StringIO(src), minify=True))
github hustlzp / Flask-Boost / flask_boost / project / application / utils / assets.py View on Github external
page_css_suffix = "}"

    page_root_path = os.path.join(static_path, page_root_path)
    for subdir in _get_immediate_subdirectories(page_root_path):
        if subdir in blueprints:
            subdir_path = os.path.join(page_root_path, subdir)
            for file in os.listdir(subdir_path):
                if file.endswith('.css'):
                    action = file[:-4].replace('_', '-')
                    page_id = "page-%s-%s" % (subdir, action)
                    file_path = os.path.join(subdir_path, file)
                    with open(file_path) as css_file:
                        page_css_string = page_css_prefix % page_id
                        page_css_string += css_file.read()
                        page_css_string += page_css_suffix
                        page_css_string = lesscpy.compile(StringIO(page_css_string), minify=True)
                        app_css_string += page_css_string

    app_css_string = app_css_string.replace('\n', '').replace('\r', '')
    with open(os.path.join(static_path, APP_CSS), "w") as text_file:
        text_file.write(app_css_string)
    print('app.css builded.')
github insula1701 / maxpress / maxpress.py View on Github external
def compile_styles(file=join_path(ROOT, 'less', 'default.less')):
    with open(file, encoding='utf-8') as raw_file:
        raw_text = raw_file.read()

    css = lesscpy.compile(StringIO(raw_text))
    with open(join_path(ROOT, 'css', 'default.css'), 'w', encoding='utf-8') as css_file:
        css_file.write(css)
github manatlan / vbuild / vbuild / __init__.py View on Github external
""" Apply css-preprocessing on css rules (according css.type) using a partial or not
        return the css pre-processed
    """
    if cnt.type in ["scss", "sass"]:
        if hasSass:
            from scss.compiler import compile_string  # lang="scss"

            return compile_string(partial + "\n" + cnt.value)
        else:
            print("***WARNING*** : miss 'sass' preprocessor : sudo pip install pyscss")
            return cnt.value
    elif cnt.type in ["less"]:
        if hasLess:
            import lesscpy, six

            return lesscpy.compile(
                six.StringIO(partial + "\n" + cnt.value), minify=True
            )
        else:
            print("***WARNING*** : miss 'less' preprocessor : sudo pip install lesscpy")
            return cnt.value
    else:
        return cnt.value
github AnyChart / AnyChart / build.py View on Github external
css_src_path = os.path.join(PROJECT_PATH, 'css', 'anychart.less')
        css_out_path = os.path.join(output, 'anychart-ui.css')
        css_min_out_path = os.path.join(output, 'anychart-ui.min.css')

        header = '\n'.join(['/*!',
                            ' '.join([' * AnyChart is lightweight robust charting library with great API and Docs, '
                                      'that works with your stack and has tons of chart types and features.']),
                            ' * Version: %s',
                            ' * License: https://www.anychart.com/buy/',
                            ' * Contact: sales@anychart.com',
                            ' * Copyright: AnyChart.com %s. All rights reserved.',
                            ' */']) % (time.strftime('%Y-%m-%d'), time.strftime('%Y')) + '\n'

        # Less
        with open(css_out_path, 'w') as f:
            f.write(header + lesscpy.compile(css_src_path))

        # Minify
        with open(css_min_out_path, 'w') as f:
            f.write(header + lesscpy.compile(css_src_path, xminify=True))

        if kwargs['gzip']:
            __gzip_file(css_out_path)
            __gzip_file(css_min_out_path)

    except ImportError:
        raise ImportError('Please install lesscpy manually first.')