|
1 | 1 | import os |
2 | | -from pathlib import Path |
3 | | - |
4 | 2 | import dash |
5 | | -from jinja2 import Environment, FileSystemLoader |
| 3 | +import dash_bootstrap_components as dbc |
6 | 4 |
|
7 | 5 | from .theme_explorer import app as theme_explorer |
8 | 6 |
|
9 | 7 | SERVE_LOCALLY = os.getenv("DBC_DOCS_MODE", "production") == "dev" |
10 | | - |
11 | | -HERE = Path(__file__).parent |
12 | | -TEMPLATES = HERE.parent / "templates" |
13 | | - |
14 | | -INDEX_STRING_TEMPLATE = """{% extends "theme-explorer.html" %} |
15 | | -{% block head %} |
16 | | -{{ super() }} |
17 | | -{{ "{%metas%}{%css%}" }} |
18 | | -{% endblock %} |
19 | | -{% block title %} |
20 | | -<title>{{ "{%title%}" }}</title> |
21 | | -{% endblock %} |
22 | | -{% block content %} |
23 | | -{{ "{%app_entry%}" }} |
24 | | -{% endblock %} |
25 | | -{% block code %}<CODE>{% endblock %} |
26 | | -{% block scripts %} |
27 | | -<footer> |
28 | | - {{ "{%config%}{%scripts%}{%renderer%}" }} |
29 | | - {{ super() }} |
30 | | -</footer> |
31 | | -{% endblock %} |
32 | | -""" |
| 8 | +FA = "https://use.fontawesome.com/releases/v5.15.3/css/all.css" |
| 9 | + |
| 10 | +SHEETS = [ |
| 11 | + ("bootstrap", dbc.themes.BOOTSTRAP), |
| 12 | + ("cerulean", dbc.themes.CERULEAN), |
| 13 | + ("cosmo", dbc.themes.COSMO), |
| 14 | + ("cyborg", dbc.themes.CYBORG), |
| 15 | + ("darkly", dbc.themes.DARKLY), |
| 16 | + ("flatly", dbc.themes.FLATLY), |
| 17 | + ("journal", dbc.themes.JOURNAL), |
| 18 | + ("litera", dbc.themes.LITERA), |
| 19 | + ("lumen", dbc.themes.LUMEN), |
| 20 | + ("lux", dbc.themes.LUX), |
| 21 | + ("materia", dbc.themes.MATERIA), |
| 22 | + ("minty", dbc.themes.MINTY), |
| 23 | + ("pulse", dbc.themes.PULSE), |
| 24 | + ("sandstone", dbc.themes.SANDSTONE), |
| 25 | + ("simplex", dbc.themes.SIMPLEX), |
| 26 | + ("sketchy", dbc.themes.SKETCHY), |
| 27 | + ("slate", dbc.themes.SLATE), |
| 28 | + ("solar", dbc.themes.SOLAR), |
| 29 | + ("spacelab", dbc.themes.SPACELAB), |
| 30 | + ("superhero", dbc.themes.SUPERHERO), |
| 31 | + ("united", dbc.themes.UNITED), |
| 32 | + ("yeti", dbc.themes.YETI), |
| 33 | +] |
33 | 34 |
|
34 | 35 |
|
35 | 36 | def register_apps(): |
36 | | - env = Environment(loader=FileSystemLoader(TEMPLATES.as_posix())) |
37 | | - template = env.from_string(INDEX_STRING_TEMPLATE) |
38 | | - template = template.render() |
39 | | - |
40 | | - code = (HERE / "theme_explorer.py").read_text() |
41 | | - |
42 | | - new_theme_explorer = dash.Dash( |
43 | | - external_stylesheets=["/static/loading.css"], |
44 | | - requests_pathname_prefix="/docs/themes/explorer/", |
45 | | - suppress_callback_exceptions=True, |
46 | | - serve_locally=SERVE_LOCALLY, |
47 | | - index_string=template.replace("<CODE>", code), |
48 | | - update_title=None, |
49 | | - ) |
50 | | - |
51 | | - new_theme_explorer.title = "Theme explorer - dbc docs" |
52 | | - new_theme_explorer.layout = theme_explorer.layout |
53 | | - new_theme_explorer.callback_map = theme_explorer.callback_map |
54 | | - new_theme_explorer._callback_list = new_theme_explorer._callback_list |
55 | | - return {"/docs/themes/explorer": new_theme_explorer} |
| 37 | + apps = {} |
| 38 | + |
| 39 | + for name, sheet in SHEETS: |
| 40 | + new_theme_explorer = dash.Dash( |
| 41 | + external_stylesheets=[FA, sheet, "/static/loading.css"], |
| 42 | + requests_pathname_prefix=f"/docs/themes/explorer/{name}/", |
| 43 | + suppress_callback_exceptions=True, |
| 44 | + serve_locally=SERVE_LOCALLY, |
| 45 | + update_title=None, |
| 46 | + ) |
| 47 | + |
| 48 | + new_theme_explorer.title = f"Theme explorer - {name} - dbc docs" |
| 49 | + new_theme_explorer.layout = theme_explorer.layout |
| 50 | + new_theme_explorer.callback_map = theme_explorer.callback_map |
| 51 | + new_theme_explorer._callback_list = theme_explorer._callback_list |
| 52 | + apps[f"/docs/themes/explorer/{name}"] = new_theme_explorer |
| 53 | + |
| 54 | + return apps |
0 commit comments