Ejemplo n.º 1
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_dir = str(static_path.parent / "scss")
        output_dir = str(static_path)
        sass_compile(dirname=(source_dir, output_dir),
                     output_style="compressed")
Ejemplo n.º 2
0
def render(attributes):
    font = attributes.get(b'font', DEFAULTS[b'font']).decode('utf-8')
    sass_variables = "$font: '%s'\n" % font
    sass_variables += '$main-size: %spx\n' % attributes.get(b'size', DEFAULTS[b'size']).decode('utf-8')
    sass_variables += '$body-color: %s\n' % attributes.get(b'background', DEFAULTS[b'background']).decode('utf-8')
    sass_variables += '$back-color: %s\n' % attributes.get(b'color', DEFAULTS[b'color']).decode('utf-8')
    sass_file = sass_variables + open('assets/styles/main.sass', 'r').read()
    css_output = sass_compile(string=sass_file, indented=True)

    formatter = HtmlFormatter(style=attributes.get(b'theme', DEFAULTS[b'theme']).decode('utf-8'))
    style = css_output + formatter.get_style_defs()

    language = attributes.get(b'language')
    language = language and language.decode('utf-8')
    filename = attributes.get(b'filename')
    filename = filename and filename.decode('utf-8')

    try:
        lexer = get_lexer_by_name(language)
    except ClassNotFound:
        lexer = get_lexer_for_filename(filename)

    highlighted = highlight(attributes.get(b'code').decode('utf-8'), lexer, formatter)

    return render_template(
        'index.jinja2',
        language=language or lexer.name,
        filename=filename,
        highlighted=highlighted,
        style=style,
        font=font
    )
Ejemplo n.º 3
0
 def _compile_scss(self, environment: str, files: List[str]) -> None:
     """
     Compiles sass and save as a css file
     """
     file_content: str = sass_compile(string=(''.join(files)),
                                      include_paths=('resources/scss', ),
                                      output_style='compressed')
     file_location: str = f'{self._project_name}/{environment}/css/main.css'
     self._save_file(file_location, file_content)
Ejemplo n.º 4
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 / "quantecon-book-theme.css"
    if not compiled_css_file.exists():
        source_dir = str(static_path.parent / "scss")
        output_dir = str(static_path)
        sass_compile(dirname=(source_dir, output_dir), output_style="compressed")

    # copying plugins
    if "plugins_list" in app.config.html_theme_options:
        outdir = app.outdir + "/plugins"
        ensuredir(outdir)
        for i, asset in enumerate(app.config.html_theme_options["plugins_list"]):
            assetname = Path(asset).name
            copy_asset(app.confdir + "/" + asset, outdir)
            app.config.html_theme_options["plugins_list"][i] = "plugins/" + assetname
Ejemplo n.º 5
0
    def build(self, ID):
        try:
            ConfigData = self.Config.get(ID)
            ConfigType = ConfigData.get("Type")

            if ConfigType == "sass":
                SassSource = ConfigData.get("source")
                SassOutput = ConfigData.get("output")
                SassStyle = ConfigData.get("output_style")
                SassComment = ConfigData.get("source_comments")
                Filepath = path.join(self.BasePath, SassSource)
                String = sass_compile(filename=Filepath,
                                      output_style=SassStyle,
                                      source_comments=SassComment)

                # Detect new import
                self.get_sass_imported(Filepath, ID)

                # Save
                FileWrite = open(path.join(self.BasePath, SassOutput), "w")
                FileWrite.write(String)
                FileWrite.close()

            elif ConfigType == "js":
                JSInclude = ConfigData.get("include")
                JSOutput = ConfigData.get("output")
                JSString = ""

                # Join
                for i in JSInclude:
                    Filepath = path.join(self.BasePath, i)
                    String = self.read_file(Filepath)
                    JSString += String

                # Save
                JSString = jsmin(JSString)
                FileWrite = open(path.join(self.BasePath, JSOutput), "w")
                FileWrite.write(JSString)
                FileWrite.close()

        except Exception as e:
            echo_click(" * Error:", e, Color="red")
Ejemplo n.º 6
0
def sass(c, compress=False):
    """Compile sass files"""
    style = "expanded"
    if compress:
        style = "compressed"
    sass_compile(dirname=(SASS_SRC, SASS_DEST), output_style=style)