2023-09-06 13:44:00 +01:00
|
|
|
# from scss.compiler import compile_string
|
|
|
|
|
|
|
|
from pygments.formatters import html
|
|
|
|
from sanic import Sanic
|
2023-10-25 01:03:35 +01:00
|
|
|
from sass import compile as compile_scss
|
2023-09-06 13:44:00 +01:00
|
|
|
|
2023-10-25 01:03:35 +01:00
|
|
|
from webapp.display.code_style import SanicCodeStyle
|
2023-09-06 13:44:00 +01:00
|
|
|
|
2023-10-25 03:02:26 +01:00
|
|
|
|
2023-09-06 13:44:00 +01:00
|
|
|
def setup_style(app: Sanic) -> None:
|
|
|
|
index = app.config.STYLE_DIR / "index.scss"
|
|
|
|
style_output = app.config.PUBLIC_DIR / "assets" / "style.css"
|
|
|
|
code_output = app.config.PUBLIC_DIR / "assets" / "code.css"
|
|
|
|
|
|
|
|
@app.before_server_start
|
|
|
|
async def setup(app: Sanic):
|
|
|
|
scss = compile_scss(
|
|
|
|
string=index.read_text(),
|
|
|
|
include_paths=[
|
|
|
|
str(app.config.NODE_MODULES_DIR),
|
|
|
|
str(app.config.STYLE_DIR),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
style_output.write_text(scss)
|
|
|
|
formatter = html.HtmlFormatter(
|
|
|
|
style=SanicCodeStyle, full=True, cssfile=code_output
|
|
|
|
)
|
|
|
|
code_output.write_text(formatter.get_style_defs())
|