def compile_scss_file(self, file_name):
        """Read given SCSS file, and compile to CSS"""
        scss_source_folder = self.generator_settings['Source']['SCSS']
        scss_source_file = os.path.join(scss_source_folder, file_name)
        try:
            with open(scss_source_file, 'r', encoding='utf8') as scss_file:
                scss_data = scss_file.read()
        except:
            logging.critical('Cannot find SCSS file {0}.'.format(file_name))
        else:
            # Add variables at start of SCSS data
            scss_data = '$version: "{}";\n{}'.format(self.version, scss_data)
            scss_data = '$title: "{}";\n{}'.format(self.translations['project_title'], scss_data)
            scss_data = '$website: "{}";\n{}'.format(self.guide_settings['website'], scss_data)
            scss_data = '$version_number: "{}";\n{}'.format(self.generator_settings['General']['Version Number'], scss_data)
            if self.output_type == WEB:
                font_path_prefix = '..'
            elif self.output_type == PDF:
                font_path_prefix = 'generator'
            scss_data = '$font-path-prefix: "{}";\n{}'.format(font_path_prefix, scss_data)

            # This lists all subfolders of SCSS source folder, this may cause issues
            # later, but is an effective solution for the moment
            scss_source_folders = [x[0] for x in os.walk(scss_source_folder)]
            compiled_css = compile_string(scss_data, search_path=scss_source_folders, output_style='compressed')
            return compiled_css
    def compile_scss_file(self, file_name):
        """Read given SCSS file, and compile to CSS"""
        scss_source_folder = self.generator_settings['Source']['SCSS']
        scss_source_file = os.path.join(scss_source_folder, file_name)
        try:
            with open(scss_source_file, 'r', encoding='utf8') as scss_file:
                scss_data = scss_file.read()
        except:
            logging.critical('Cannot find SCSS file {0}.'.format(file_name))
        else:
            # Add variables at start of SCSS data
            scss_data = '$version: "{}";\n{}'.format(self.version, scss_data)
            scss_data = '$title: "{}";\n{}'.format(
                self.translations['project_title'], scss_data)
            scss_data = '$website: "{}";\n{}'.format(
                self.guide_settings['website'], scss_data)
            scss_data = '$version_number: "{}";\n{}'.format(
                self.generator_settings['General']['Version Number'],
                scss_data)
            if self.output_type == WEB:
                font_path_prefix = '..'
            elif self.output_type == PDF:
                font_path_prefix = 'generator'
            scss_data = '$font-path-prefix: "{}";\n{}'.format(
                font_path_prefix, scss_data)

            # This lists all subfolders of SCSS source folder, this may cause issues
            # later, but is an effective solution for the moment
            scss_source_folders = [x[0] for x in os.walk(scss_source_folder)]
            compiled_css = compile_string(scss_data,
                                          search_path=scss_source_folders,
                                          output_style='compressed')
            return compiled_css
Exemple #3
0
def preProcessCSS(cnt, partial=""):
    """ 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
Exemple #4
0
def transpile_scss():
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        from scss.compiler import compile_string  # type: ignore

        with open(os.path.join(LNBITS_PATH, "static/scss/base.scss")) as scss:
            with open(os.path.join(LNBITS_PATH, "static/css/base.css"), "w") as css:
                css.write(compile_string(scss.read()))
Exemple #5
0
def compile_css():
    with sass_file_path.open('rt') as sass_content:
        css_content: str = compile_string(sass_content.read(),
                                          output_style='compressed')
    css_filename: PosixPath = build_dir.joinpath('dummy.filename').with_name(
        Path(sass_file_path.stem).with_suffix('.css').as_posix())

    with css_filename.open('wt') as file:
        file.write(css_content)
    def test_1(self):

        extension = pyscss_pkg_resources.PkgResourcesExtension('pyscss_pkg_resources', '')
        compiler = scss.compiler.Compiler(extensions=(extension, ))
        out = compiler.compile_string('@import "test.scss";')
        self.assertEqual(
            'a {\n'
            '  color: red; }\n',
            out)
Exemple #7
0
def do_scss(scss_fnames, css_fname):
    scss = ''
    for scss_fn in scss_fnames:
        with open(os.path.join(PELICAN_ROOT, 'theme-bnc', 'static', 'css', scss_fn), 'r') as scss_file:
            scss += scss_file.read()
    from scss.compiler import compile_string
    css = compile_string(scss, output_style=SCSS_STYLE,
        search_path=(os.path.join(PELICAN_ROOT, 'theme-bnc', 'static', 'css')))
    with open(os.path.join(PELICAN_ROOT, 'theme-bnc', 'static', 'css', css_fname), 'w') as css_file:
        css_file.write(css)
def build_css():
	scss_fragments = []

	for filename in sorted(os.listdir(CSS_FRAGMENT_DIR)):
		if any(filename.endswith(ext) for ext in CSS_INCLUDE_EXTENSIONS):
			with open(os.path.join(CSS_FRAGMENT_DIR, filename), 'r') as readfile:
				scss_fragments.append(readfile.read())

	scss = '\n'.join(scss_fragments)

	css = compile_string(scss)

	with open(CSS_OUTPUT_FILENAME, 'w') as outfile:
		outfile.write(trim_css(css))
Exemple #9
0
def do_scss(scss_fnames, css_fname):
    scss = ''
    for scss_fn in scss_fnames:
        with open(
                os.path.join(PELICAN_ROOT, 'theme-bnc', 'static', 'css',
                             scss_fn), 'r') as scss_file:
            scss += scss_file.read()
    from scss.compiler import compile_string
    css = compile_string(scss,
                         output_style=SCSS_STYLE,
                         search_path=(os.path.join(PELICAN_ROOT, 'theme-bnc',
                                                   'static', 'css')))
    with open(
            os.path.join(PELICAN_ROOT, 'theme-bnc', 'static', 'css',
                         css_fname), 'w') as css_file:
        css_file.write(css)
    def compile_scss_file(self, file_name):
        """Read given SCSS file, and compile to CSS,
        store in file object, and add to required CSS files
        """
        scss_source_folder = self.generator_settings['Source']['SCSS']
        scss_source_file = os.path.join(scss_source_folder, file_name)
        try:
            with open(scss_source_file, 'r', encoding='utf8') as scss_file:
                scss_data = scss_file.read()
        except:
            logging.critical('Cannot find SCSS file {0}.'.format(file_name))
        else:
            # Add version variable at start of SCSS data
            scss_data = "$version: " + self.version + ";\n" + scss_data

            # This lists all subfolders of SCSS source folder, this may cause issues
            # later, but is an effective solution for the moment
            scss_source_folders = [x[0] for x in os.walk(scss_source_folder)]
            compiled_css = compile_string(scss_data, search_path=scss_source_folders, output_style='compressed')
            return compiled_css
Exemple #11
0
    def compile_scss_file(self, file_name):
        """Read given SCSS file, and compile to CSS,
        store in file object, and add to required CSS files
        """
        scss_source_folder = self.generator_settings['Source']['SCSS']
        scss_source_file = os.path.join(scss_source_folder, file_name)
        try:
            with open(scss_source_file, 'r', encoding='utf8') as scss_file:
                scss_data = scss_file.read()
        except:
            logging.critical('Cannot find SCSS file {0}.'.format(file_name))
        else:
            # Add version variable at start of SCSS data
            scss_data = "$version: " + self.version + ";\n" + scss_data

            # This lists all subfolders of SCSS source folder, this may cause issues
            # later, but is an effective solution for the moment
            scss_source_folders = [x[0] for x in os.walk(scss_source_folder)]
            compiled_css = compile_string(scss_data,
                                          search_path=scss_source_folders,
                                          output_style='compressed')
            return compiled_css
Exemple #12
0
def transpile_scss():
    with open(os.path.join(LNBITS_PATH, "static/scss/base.scss")) as scss:
        with open(os.path.join(LNBITS_PATH, "static/css/base.css"),
                  "w") as css:
            css.write(compile_string(scss.read()))
Exemple #13
0
def test_missing_import():
    with pytest.raises(SassImportError):
        compile_string("""
            @import "bogus-file";
        """)