コード例 #1
0
ファイル: conftest.py プロジェクト: verysure/pyScss
    def runtest(self):
        scss_file = self.fspath
        css_file = scss_file.new(ext='css')

        with css_file.open('rb') as fh:
            # Output is Unicode, so decode this here
            expected = fh.read().decode('utf8')

        scss.config.STATIC_ROOT = str(scss_file.dirpath('static'))

        actual = compile_file(
            str(scss_file),
            output_style='expanded',
            search_path=[
                str(scss_file.dirpath('include')),
                str(scss_file.dirname),
            ],
            extensions=[
                CoreExtension,
                ExtraExtension,
                FontsExtension,
                CompassExtension,
            ],
        )

        # Normalize leading and trailing newlines
        actual = actual.strip('\n')
        expected = expected.strip('\n')

        assert expected == actual
コード例 #2
0
def compile(file):
    log = logger.get('SCSS')
    p = path.splitext(file)[0]
    if not path.exists('web/css'):
        mkdir('web/css')
    css_file = path.join('web/css', p + '.css')
    scss_file = path.join('web/scss', p + '.scss')
    c = False
    if path.exists(css_file):
        if path.getmtime(css_file) < path.getmtime(scss_file):
            c = True
    else:
        c = True

    if c:
        log.info(f'Recompiling {css_file}')
        s = None
        try:
            s = compile_file(scss_file)
        except scss.errors.SassError as e:
            log.error(f'SCSS error on file {scss_file}:')
            log.error(e)
            s = e.to_css() + 'body > * {visibility: hidden}'
        if s:
            s = rcssmin.cssmin(s)
            with open(css_file, 'w') as css:
                # log.info(s)
                css.write(s)

    else:
        log.info(f'{css_file} already compiled')
コード例 #3
0
ファイル: conftest.py プロジェクト: asfaltboy/pyScss
    def runtest(self):
        scss_file = self.fspath
        css_file = scss_file.new(ext='css')

        with css_file.open('rb') as fh:
            # Output is Unicode, so decode this here
            expected = fh.read().decode('utf8')

        scss.config.STATIC_ROOT = str(scss_file.dirpath('static'))

        actual = compile_file(
            str(scss_file),
            output_style='expanded',
            search_path=[
                str(scss_file.dirpath('include')),
                str(scss_file.dirname),
            ],
            extensions=[
                CoreExtension,
                ExtraExtension,
                FontsExtension,
                CompassExtension,
            ],
        )

        # Normalize leading and trailing newlines
        actual = actual.strip('\n')
        expected = expected.strip('\n')

        assert expected == actual
コード例 #4
0
ファイル: conftest.py プロジェクト: jrcartee/pyScss
    def runtest(self):
        scss_file = Path(str(self.fspath))
        css_file = scss_file.with_suffix('.css')

        with css_file.open('rb') as fh:
            # Output is Unicode, so decode this here
            expected = fh.read().decode('utf8')

        scss.config.STATIC_ROOT = str(scss_file.parent / 'static')

        search_path = []
        include = scss_file.parent / 'include'
        if include.exists():
            search_path.append(include)
        search_path.append(scss_file.parent)

        actual = compile_file(
            scss_file,
            output_style='expanded',
            search_path=search_path,
            extensions=[
                CoreExtension,
                ExtraExtension,
                FontsExtension,
                CompassExtension,
            ],
        )

        # Normalize leading and trailing newlines
        actual = actual.strip('\n')
        expected = expected.strip('\n')

        assert expected == actual
コード例 #5
0
def compile(file_name):
    #data = Compiler().compile_string("a { color: red + green; }")
    try:
        data = compile_file(file_name)
        return data
    except SassEvaluationError as e:
        raise SassException(e)
コード例 #6
0
def compile(file_name):
    #data = Compiler().compile_string("a { color: red + green; }")
    try:
        data = compile_file(file_name)
        return data
    except SassEvaluationError as e:
        raise SassException(e)
コード例 #7
0
def render_file(filename):
    if filename.endswith('.scss') or filename.endswith('.css'):
        return compile_file(
            filename,
            output_style='legacy' if settings.DEBUG else 'compressed',
        )

    return render(filename)
コード例 #8
0
ファイル: build_critical.py プロジェクト: iqbalali/myblog
def compile_critical(pelican):
    """Add Webassets to Jinja2 extensions in Pelican settings."""
    theme_path = os.path.join(pelican.settings.get('PATH'), os.pardir,
                              'pelican_site', 'theme')
    critical_css_path = os.path.join(theme_path, 'static', 'scss',
                                     'critical.scss')
    compiled_css = compile_file(critical_css_path)
    minified_css = cssmin(compiled_css)
    with open(os.path.join(theme_path, 'templates', 'critical.css'), 'w') as f:
        f.write(minified_css)
コード例 #9
0
def add_static_path(app):
    static_path = Path(__file__).parent.joinpath("static").absolute()
    app.config.html_static_path.append(str(static_path))

    # Compile the css file if it's not been compiled already
    compiled_css_file = static_path / "sphinx-book-theme.css"
    if not compiled_css_file.exists():
        source_file = str(static_path.parent / "scss" /
                          "sphinx-book-theme.scss")
        css = compile_file(source_file, output_style="compressed")
        with open(compiled_css_file, "w") as f:
            f.write(css)
コード例 #10
0
ファイル: build_critical.py プロジェクト: rjames86/myblog
def compile_critical(pelican):
    """Add Webassets to Jinja2 extensions in Pelican settings."""
    theme_path = os.path.join(pelican.settings.get('PATH'),
                              os.pardir,
                              'pelican_site',
                              'theme')
    critical_css_path = os.path.join(theme_path,
                                     'static',
                                     'scss',
                                     'critical.scss')
    compiled_css = compile_file(critical_css_path)
    minified_css = cssmin(compiled_css)
    with open(os.path.join(theme_path, 'templates', 'critical.css'), 'w') as f:
        f.write(minified_css)
コード例 #11
0
 def publish_css(self):
     """Compile and publish all SCSS files in the root SCSS directory."""
     scss_path = os.path.join(SUPPORT_ROOT, 'scss')
     css_path = os.path.join(self.output_dir, 'assets', 'css')
     os.makedirs(css_path, exist_ok=True)
     for scss_file in os.listdir(scss_path):
         if not scss_file.endswith('.scss'):
             continue
         css_file = os.path.join(
             css_path,
             re.sub(r'\.scss$', '.css', scss_file),
         )
         with io.open(css_file, 'w') as f:
             f.write(compile_file(os.path.join(scss_path, scss_file)))
         self.log(f'Successfully wrote {css_file}.')
コード例 #12
0
ファイル: conftest.py プロジェクト: 4teamwork/pyScss
    def runtest(self):
        scss_file = Path(str(self.fspath))
        css_file = scss_file.with_suffix('.css')

        with css_file.open('rb') as fh:
            # Output is Unicode, so decode this here
            expected = fh.read().decode('utf8')

        scss.config.STATIC_ROOT = str(scss_file.parent / 'static')

        search_path = []
        include = scss_file.parent / 'include'
        if include.exists():
            search_path.append(include)
        search_path.append(scss_file.parent)

        try:
            actual = compile_file(
                scss_file,
                output_style='expanded',
                search_path=search_path,
                extensions=[
                    CoreExtension,
                    ExtraExtension,
                    FontsExtension,
                    CompassExtension,
                ],
            )
        except SassEvaluationError as e:
            # Treat any missing dependencies (PIL not installed, fontforge not
            # installed) as skips
            # TODO this is slightly cumbersome and sorta defeats the purpose of
            # having separate exceptions
            if isinstance(e.exc, SassMissingDependency):
                pytest.skip(e.format_message())
            else:
                raise

        # Normalize leading and trailing newlines
        actual = actual.strip('\n')
        expected = expected.strip('\n')

        assert expected == actual
コード例 #13
0
ファイル: scss_to_css.py プロジェクト: keiwop/stylish_themes
def compile_scss():
	scss_list = glob.glob("./*.scss")
	print("\n\n\n\nSCSS_FILES:", scss_list)
	for scss_path in scss_list:
		css_path = scss_path.replace("scss", "css")
		print("\nscss path:", scss_path)
		print("css path:", css_path)
#		print("app path:", self.app_path)
#		asset_path = self.app_path + "/icons/assets/checkbox-checked_"
#		asset_path += os.path.basename(scss_path).split(".")[0] + ".svg"
		print("scss file:", os.path.basename(scss_path))
#		print("asset_path:", asset_path)
		
		namespace = Namespace()
#		namespace.set_variable("$asset_path", String(asset_path))
		css_data = compiler.compile_file(scss_path, namespace=namespace)
		print("css:", css_data)
		with open(css_path, "w") as css_file:
			css_file.write(css_data)
コード例 #14
0
ファイル: conftest.py プロジェクト: ziotoie00/pyScss
    def runtest(self):
        scss_file = Path(str(self.fspath))
        css_file = scss_file.with_suffix('.css')

        with css_file.open('rb') as fh:
            # Output is Unicode, so decode this here
            expected = fh.read().decode('utf8')

        scss.config.STATIC_ROOT = str(scss_file.parent / 'static')

        search_path = []
        include = scss_file.parent / 'include'
        if include.exists():
            search_path.append(include)
        search_path.append(scss_file.parent)

        try:
            actual = compile_file(
                scss_file,
                output_style='expanded',
                search_path=search_path,
                extensions=[
                    CoreExtension,
                    ExtraExtension,
                    FontsExtension,
                    CompassExtension,
                ],
            )
        except SassEvaluationError as e:
            # Treat any missing dependencies (PIL not installed, fontforge not
            # installed) as skips
            # TODO this is slightly cumbersome and sorta defeats the purpose of
            # having separate exceptions
            if isinstance(e.exc, SassMissingDependency):
                pytest.skip(e.format_message())
            else:
                raise

        # Normalize leading and trailing newlines
        actual = actual.strip('\n')
        expected = expected.strip('\n')

        assert expected == actual
コード例 #15
0
ファイル: compile_scss.py プロジェクト: keiwop/Nameless-Theme
#! /usr/bin/env python3

from scss.namespace import Namespace
from scss.types import String
from scss import compiler
import glob
import os

scss_list = glob.glob("gnome-shell/*.scss")
print("\nSCSS_FILES:", scss_list)
for scss_path in scss_list:
	css_path = scss_path.replace("scss", "css")
	print("\nscss path:", scss_path)
	print("css path:", css_path)
	
	namespace = Namespace()
	namespace.set_variable("$variant", String("light"))
	css_data = compiler.compile_file(scss_path, namespace=namespace)
	with open(css_path, "w") as css_file:
		css_file.write(css_data)

コード例 #16
0
def scss(css_file: str):
    """Compile the given SCSS file and return it."""
    scss_file = re.sub(r'\.css$', '.scss', css_file)
    css = compile_file(f'{ROOT}/aip_site/support/scss/{scss_file}')
    return flask.Response(css, mimetype='text/css')