Skip to content

Commit

Permalink
Support bootswatch_theme as parameter to load_css
Browse files Browse the repository at this point in the history
  • Loading branch information
jbussdieker committed Sep 5, 2024
1 parent b08fcc2 commit 75e79c3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions flask_bootstrap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,16 @@ def init_app(self, app):
'row row-cols-lg-auto g-3 align-items-center'
) # Bootstrap 5 only

def load_css(self, version=None, bootstrap_sri=None):
def load_css(self, version=None, bootstrap_sri=None, bootswatch_theme=None):
"""Load Bootstrap's css resources with given version.
.. versionadded:: 0.1.0
:param version: The version of Bootstrap.
:param bootswatch_theme: Set the bootswatch theme at the request/session level.
"""
serve_local = current_app.config['BOOTSTRAP_SERVE_LOCAL']
bootswatch_theme = current_app.config['BOOTSTRAP_BOOTSWATCH_THEME']
bootswatch_theme = bootswatch_theme or current_app.config['BOOTSTRAP_BOOTSWATCH_THEME']
if version is None:
version = self.bootstrap_version
bootstrap_sri = self._get_sri('bootstrap_css', version, bootstrap_sri)
Expand Down
6 changes: 6 additions & 0 deletions tests/test_bootstrap4/test_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ def test_load_css_with_default_versions(self, bootstrap):
'crossorigin="anonymous">'
assert bootstrap_css in rv

def test_load_css_with_bootswatch_theme(self, bootstrap):
rv = bootstrap.load_css(bootswatch_theme="mist")
bootstrap_css = f'<link rel="stylesheet" href="{CDN_BASE}/bootswatch@{bootstrap.bootstrap_version}/' \
f'dist/mist/bootstrap.min.css"'
assert bootstrap_css in rv

def test_load_css_with_non_default_versions(self, bootstrap):
def _check_assertions(rv):
assert 'bootstrap.min.css' in rv
Expand Down

0 comments on commit 75e79c3

Please sign in to comment.