Skip to content

Commit 75e79c3

Browse files
committed
Support bootswatch_theme as parameter to load_css
1 parent b08fcc2 commit 75e79c3

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

flask_bootstrap/__init__.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,16 @@ def init_app(self, app):
8989
'row row-cols-lg-auto g-3 align-items-center'
9090
) # Bootstrap 5 only
9191

92-
def load_css(self, version=None, bootstrap_sri=None):
92+
def load_css(self, version=None, bootstrap_sri=None, bootswatch_theme=None):
9393
"""Load Bootstrap's css resources with given version.
9494
9595
.. versionadded:: 0.1.0
9696
9797
:param version: The version of Bootstrap.
98+
:param bootswatch_theme: Set the bootswatch theme at the request/session level.
9899
"""
99100
serve_local = current_app.config['BOOTSTRAP_SERVE_LOCAL']
100-
bootswatch_theme = current_app.config['BOOTSTRAP_BOOTSWATCH_THEME']
101+
bootswatch_theme = bootswatch_theme or current_app.config['BOOTSTRAP_BOOTSWATCH_THEME']
101102
if version is None:
102103
version = self.bootstrap_version
103104
bootstrap_sri = self._get_sri('bootstrap_css', version, bootstrap_sri)

tests/test_bootstrap4/test_bootstrap.py

+6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ def test_load_css_with_default_versions(self, bootstrap):
3838
'crossorigin="anonymous">'
3939
assert bootstrap_css in rv
4040

41+
def test_load_css_with_bootswatch_theme(self, bootstrap):
42+
rv = bootstrap.load_css(bootswatch_theme="mist")
43+
bootstrap_css = f'<link rel="stylesheet" href="{CDN_BASE}/bootswatch@{bootstrap.bootstrap_version}/' \
44+
f'dist/mist/bootstrap.min.css"'
45+
assert bootstrap_css in rv
46+
4147
def test_load_css_with_non_default_versions(self, bootstrap):
4248
def _check_assertions(rv):
4349
assert 'bootstrap.min.css' in rv

0 commit comments

Comments
 (0)