diff --git a/docs/blueprint-init.html b/docs/blueprint-init.html new file mode 100644 index 00000000..7d87d7fc --- /dev/null +++ b/docs/blueprint-init.html @@ -0,0 +1,263 @@ + + +
+ +Blueprint(dunder_name: str, config_file: str = "config.toml") -> None
+
Initializes the Flask-Imp Blueprint.
+dunder_name
should always be set to __name__
config_file
is the name of the config file to load.
+It will be loaded from the same directory as the __init__.py
file.
import_models(folder: str = "models") -> None
+
Will import all the models from the given folder relative to the Blueprint's root directory.
+Works the same as Imp.x / import_models but relative to the Blueprint root.
+Blueprint models will also be available in the Imp.x / model lookup.
+my_blueprint/
+├── routes/...
+├── static/...
+├── templates/...
+│
+├── animal_models.py
+│
+├── __init__.py
+└── config.toml
+
or
+my_blueprint/
+├── routes/...
+├── static/...
+├── templates/...
+│
+├── models/
+│ └── animals.py
+│
+├── __init__.py
+└── config.toml
+
File: my_blueprint/__init__.py
from flask_imp import Blueprint
+
+bp = Blueprint(__name__)
+
+bp.import_resources("routes")
+bp.import_models("animal_models.py")
+
or
+from flask_imp import Blueprint
+
+bp = Blueprint(__name__)
+
+bp.import_resources("routes")
+bp.import_models("models")
+
File: my_blueprint/animal_models.py
or my_blueprint/models/animals.py
from app import db
+
+
+class Animals(db.Model):
+ animal_id = db.Column(db.Integer, primary_key=True)
+ name = db.Column(db.String(64), index=True, unique=True)
+ species = db.Column(db.String(64), index=True, unique=True)
+
init_app(
+ app: Flask,
+ app_config_file: Optional[str] = None,
+ ignore_missing_env_variables: bool = False
+) -> None
+# -or-
+Imp(
+ app: Optional[Flask] = None,
+ app_config_file: Optional[str] = None,
+ ignore_missing_env_variables: bool = False
+) -> None
+
Initializes the flask app to work with flask-imp.
+If no app_config_file
specified, an attempt to read IMP_CONFIG
from the environment will be made.
If IMP_CONFIG
is not in the environment variables, an attempt to load default.config.toml
will be made.
default.config.toml
will be created, and used if not found.
If ignore_missing_env_variables
is True
, then missing environment variables will be ignored.
If ignore_missing_env_variables
is False
(default), then missing environment variables will raise a ValueError
diff --git a/docs/blueprint_x-import_nested_blueprint.html b/docs/blueprint_x-import_nested_blueprint.html index f1e8ea42..16c6ca71 100644 --- a/docs/blueprint_x-import_nested_blueprint.html +++ b/docs/blueprint_x-import_nested_blueprint.html @@ -249,7 +249,55 @@
import_nested_blueprint(self, blueprint: str) -> None
+
Import a specified Flask-Imp or standard Flask Blueprint relative to the Blueprint root.
+Works the same as Imp.x / import_blueprint but relative to the Blueprint root.
+Blueprints that are imported this way will be scoped to the parent Blueprint that imported them.
+url_for('my_blueprint.my_nested_blueprint.index')
my_blueprint/
+├── routes/...
+├── static/...
+├── templates/...
+│
+├── my_nested_blueprint/
+│ ├── routes/
+│ │ └── index.py
+│ ├── static/...
+│ ├── templates/...
+│ ├── __init__.py
+│ └── config.toml
+│
+├── __init__.py
+└── config.toml
+
File: my_blueprint/__init__.py
from flask_imp import Blueprint
+
+bp = Blueprint(__name__)
+
+bp.import_resources("routes")
+bp.import_nested_blueprint("my_nested_blueprint")
+
File: my_blueprint/my_nested_blueprint/__init__.py
from flask_imp import Blueprint
+
+bp = Blueprint(__name__)
+
+bp.import_resources("routes")
+
File: my_blueprint/my_nested_blueprint/routes/index.py
from flask import render_template
+
+from .. import bp
+
+
+@bp.route("/")
+def index():
+ return render_template(bp.tmpl("index.html"))
+
diff --git a/docs/blueprint_x-import_nested_blueprints.html b/docs/blueprint_x-import_nested_blueprints.html index 2bbfd38d..2ccf11c5 100644 --- a/docs/blueprint_x-import_nested_blueprints.html +++ b/docs/blueprint_x-import_nested_blueprints.html @@ -249,7 +249,48 @@
import_nested_blueprints(self, folder: str) -> None
+
Will import all the Blueprints from the given folder relative to the Blueprint's root directory.
+Uses Blueprint.x / import_nested_blueprint to import blueprints from +the specified folder.
+Blueprints that are imported this way will be scoped to the parent Blueprint that imported them.
+url_for('my_blueprint.nested_bp_one.index')
url_for('my_blueprint.nested_bp_two.index')
url_for('my_blueprint.nested_bp_three.index')
my_blueprint/
+├── routes/...
+├── static/...
+├── templates/...
+│
+├── nested_blueprints/
+│ │
+│ ├── nested_bp_one/
+│ │ ├── ...
+│ │ ├── __init__.py
+│ │ └── config.toml
+│ ├── nested_bp_two/
+│ │ ├── ...
+│ │ ├── __init__.py
+│ │ └── config.toml
+│ └── nested_bp_three/
+│ ├── ...
+│ ├── __init__.py
+│ └── config.toml
+│
+├── __init__.py
+└── config.toml
+
File: my_blueprint/__init__.py
from flask_imp import Blueprint
+
+bp = Blueprint(__name__)
+
+bp.import_resources("routes")
+bp.import_nested_blueprints("nested_blueprints")
+
diff --git a/docs/blueprint_x-tmpl.html b/docs/blueprint_x-tmpl.html index 6d58f716..2898ca1a 100644 --- a/docs/blueprint_x-tmpl.html +++ b/docs/blueprint_x-tmpl.html @@ -249,7 +249,37 @@
tmpl(template: str) -> str
+
Scopes the template lookup to the name of the blueprint (this takes from the __name__
attribute of the Blueprint).
Due to the way Flask templating works, and to avoid template name collisions. +It is standard practice to place the name of the Blueprint in the template path, +then to place any templates under that folder.
+my_blueprint/
+├── routes/
+│ └── index.py
+├── static/...
+│
+├── templates/
+│ └── my_blueprint/
+│ └── index.html
+│
+├── __init__.py
+└── config.toml
+
File: my_blueprint/routes/index.py
from flask import render_template
+
+from .. import bp
+
+
+@bp.route("/")
+def index():
+ return render_template(bp.tmpl("index.html"))
+
bp.tmpl("index.html")
will output "my_blueprint/index.html"
.
diff --git a/docs/imp_x-init_app-init.html b/docs/imp_x-init_app-init.html new file mode 100644 index 00000000..1602d76e --- /dev/null +++ b/docs/imp_x-init_app-init.html @@ -0,0 +1,275 @@ + + +
+ +
+ + + + + + + + + + +
+