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 @@ + + + + + Flask-Imp Blueprint __init__ | Flask-Imp + + + + + + + + + + + + + + +
+

Flask-Imp Blueprint __init__

+
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.

+ +
+ + + \ No newline at end of file diff --git a/docs/blueprint_x-import_models.html b/docs/blueprint_x-import_models.html index 01def079..f2d41d6e 100644 --- a/docs/blueprint_x-import_models.html +++ b/docs/blueprint_x-import_models.html @@ -249,7 +249,60 @@

Menu

Blueprint.import_models

- +
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)
+
+
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 @@

Menu

Blueprint.import_nested_blueprint

- +
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 @@

Menu

Blueprint.import_nested_blueprints

- +
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 @@

Menu

Blueprint.tmpl

- +
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 @@ + + + + + Imp.init_app, __init__ | Flask-Imp + + + + + + + + + + + + + + +
+

Imp.init_app, __init__

+
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

+ +
+ + + \ No newline at end of file diff --git a/docs_gen/markdown/Blueprint_x-import_models.md b/docs_gen/markdown/Blueprint_x-import_models.md index 8cb5fb49..d919ae65 100644 --- a/docs_gen/markdown/Blueprint_x-import_models.md +++ b/docs_gen/markdown/Blueprint_x-import_models.md @@ -2,3 +2,79 @@ Menu = Blueprint.x/import_models Title = Blueprint.import_models ``` + +```python +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](imp_x-import_models.html) but relative to the Blueprint root. + +Blueprint models will also be available in the [Imp.x / model](imp_x-model.html) lookup. + +```text +my_blueprint/ +├── routes/... +├── static/... +├── templates/... +│ +├── animal_models.py +│ +├── __init__.py +└── config.toml +``` + +**or** + +```text +my_blueprint/ +├── routes/... +├── static/... +├── templates/... +│ +├── models/ +│ └── animals.py +│ +├── __init__.py +└── config.toml +``` + +File: `my_blueprint/__init__.py` + +```python +from flask_imp import Blueprint + +bp = Blueprint(__name__) + +bp.import_resources("routes") +bp.import_models("animal_models.py") +``` + +**or** + +```python +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` + +```python +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) +``` + + + diff --git a/docs_gen/markdown/Blueprint_x-import_nested_blueprint.md b/docs_gen/markdown/Blueprint_x-import_nested_blueprint.md index aedf0300..d8139c3d 100644 --- a/docs_gen/markdown/Blueprint_x-import_nested_blueprint.md +++ b/docs_gen/markdown/Blueprint_x-import_nested_blueprint.md @@ -2,3 +2,69 @@ Menu = Blueprint.x/import_nested_blueprint Title = Blueprint.import_nested_blueprint ``` + +```python +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](imp_x-import_blueprint.html) 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')` + +```text +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` + +```python +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` + +```python +from flask_imp import Blueprint + +bp = Blueprint(__name__) + +bp.import_resources("routes") +``` + +File: `my_blueprint/my_nested_blueprint/routes/index.py` + +```python +from flask import render_template + +from .. import bp + + +@bp.route("/") +def index(): + return render_template(bp.tmpl("index.html")) +``` \ No newline at end of file diff --git a/docs_gen/markdown/Blueprint_x-import_nested_blueprints.md b/docs_gen/markdown/Blueprint_x-import_nested_blueprints.md index 849c5827..16bdc2a7 100644 --- a/docs_gen/markdown/Blueprint_x-import_nested_blueprints.md +++ b/docs_gen/markdown/Blueprint_x-import_nested_blueprints.md @@ -2,3 +2,58 @@ Menu = Blueprint.x/import_nested_blueprints Title = Blueprint.import_nested_blueprints ``` + +```python +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](blueprint_x-import_nested_blueprint.html) 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')` + +```text +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` + +```python +from flask_imp import Blueprint + +bp = Blueprint(__name__) + +bp.import_resources("routes") +bp.import_nested_blueprints("nested_blueprints") +``` \ No newline at end of file diff --git a/docs_gen/markdown/Blueprint_x-tmpl.md b/docs_gen/markdown/Blueprint_x-tmpl.md index e58a7e35..dd23bed6 100644 --- a/docs_gen/markdown/Blueprint_x-tmpl.md +++ b/docs_gen/markdown/Blueprint_x-tmpl.md @@ -2,3 +2,44 @@ Menu = Blueprint.x/tmpl Title = Blueprint.tmpl ``` + +```python +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. + +```text +my_blueprint/ +├── routes/ +│ └── index.py +├── static/... +│ +├── templates/ +│ └── my_blueprint/ +│ └── index.html +│ +├── __init__.py +└── config.toml +``` + +File: `my_blueprint/routes/index.py` + +```python +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"`.