-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make bootstrap available in extension resources (#7)
- Loading branch information
Showing
55 changed files
with
67,166 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from flask import Flask | ||
|
||
from bootlace.extension import Bootlace | ||
|
||
|
||
app = Flask(__name__) | ||
bootlace = Bootlace(app) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from flask import Blueprint | ||
from flask import current_app | ||
from flask import Flask | ||
from flask import url_for | ||
|
||
|
||
class Bootlace: | ||
"""Flask extension for bootlace""" | ||
|
||
def __init__(self, app: Flask | None = None) -> None: | ||
if app is not None: | ||
self.init_app(app) | ||
|
||
def init_app(self, app: Flask) -> None: | ||
"""Initialize the extension with the Flask app""" | ||
|
||
app.extensions["bootlace"] = self | ||
app.jinja_env.globals["bootlace"] = self | ||
|
||
name = app.config.setdefault("BOOTLACE_BLUEPRINT_NAME", "bootlace") | ||
|
||
blueprint = Blueprint( | ||
name, | ||
__name__, | ||
template_folder="templates", | ||
static_folder="static", | ||
static_url_path="/static/bootstrap", | ||
) | ||
|
||
app.register_blueprint(blueprint) | ||
|
||
@property | ||
def static_view(self) -> str: | ||
bp = current_app.config["BOOTLACE_BLUEPRINT_NAME"] | ||
return f"{bp}.static" | ||
|
||
@property | ||
def icons(self) -> str: | ||
"""The URL for the SVG source for the icons""" | ||
return url_for(self.static_view, filename="icons/bootstrap-icons.svg") | ||
|
||
@property | ||
def css(self) -> str: | ||
"""The URL for the Bootstrap CSS file""" | ||
return url_for(self.static_view, filename="css/bootstrap.min.css") | ||
|
||
@property | ||
def js(self) -> str: | ||
"""The URL for the Bootstrap JS file""" | ||
return url_for(self.static_view, filename="js/bootstrap.min.js") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.