Skip to content

Commit a92fc41

Browse files
committed
Fix theme explorer and make more responsive
1 parent 0547173 commit a92fc41

File tree

9 files changed

+990
-1190
lines changed

9 files changed

+990
-1190
lines changed

docs/demos/__init__.py

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,54 @@
11
import os
2-
from pathlib import Path
3-
42
import dash
5-
from jinja2 import Environment, FileSystemLoader
3+
import dash_bootstrap_components as dbc
64

75
from .theme_explorer import app as theme_explorer
86

97
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+
]
3334

3435

3536
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

Comments
 (0)