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
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')
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
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)
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)
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)
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)
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}.')
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
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)
#! /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)
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')