Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support bootswatch_theme as parameter to load_css #369

Merged
merged 1 commit into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading