Flask-Super-Macros
Super charged Jinja macros for Flask using Jinja Super Macros.
- Inspired by frontend component frameworks
- Use macros like html components
- Auto macro loader
- Compatible with Storybook
Installation
pip install flask-super-macros
Usage
from flask import Flask
from flask_super_macros import SuperMacros
app = Flask(__name__)
SuperMacros(app)
Macros will be automatically registered from:
- Macro defined using the
macrodirective in all template files called__macros__.html - Created from files with the extension
.macro.html - Created from files in the
macrosfolder
(Note: creating macros from files is the equivalent of wrapping the whole file in a macro directive)
Example macros/btn.html:
<{button class="btn" **kwargs}>{{ inner }}</{}>
You can then use this macro in any template (no need to import):
<{ btn onclick="alert('hello')" }>click me</{ btn }>
See Jinja Super Macros documentation to learn more about the new macro calling syntax.
To register macros from other files, the macro registry is available under ̀app.macros:
app.macros.register_from_template("macros.html")
You can also create macros fron functions using app.macro:
@app.macro
def btn(**kwargs):
"""<{button class="btn" **kwargs}>{{ inner }}</{}>"""
Storybook
Registered jinja macros can be viewed in Storybook using the server renderer.
Initialize your storybook project:
npx storybook@latest init -t server
Use http://localhost:5000/__storybook as the preview url.
In your story, define the component name using the parameters.server.id:
{
"title": "Button",
"parameters": {
"server": {
"id": "Button"
}
}
}
Metadata
Release files for flask-super-macros 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| flask_super_macros-0.2.0.tar.gz | 2.4 kB | Without provenance | Details for flask_super_macros-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| flask_super_macros-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for flask_super_macros-0.2.0-py3-none-any.whl |
Total release size: 5.9 kB
Release files / flask_super_macros-0.2.0.tar.gz
| Download URL | flask_super_macros-0.2.0.tar.gz |
|---|---|
| Size | 2.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0e93591823ee0ee25716f9b4f6a07bb2586f1ef1b697fdbde52d96d44362d1fc
|
|
BLAKE2b-256 checksum How to use checksums |
845d79ce3dbee3ef7d01389ba9caf053d3ee64b3ae6ad8402896368e38f1b3d9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.17
|
Release files / flask_super_macros-0.2.0-py3-none-any.whl
| Download URL | flask_super_macros-0.2.0-py3-none-any.whl |
|---|---|
| Size | 3.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dd0e95e424862e3016ebdc4347ef9d23f37bdd1e95a1ca6dbacefeb39fb18b0a
|
|
BLAKE2b-256 checksum How to use checksums |
89640bfd0a639f756ecae22e0cfd385573e519fd9100a92a3627cfa74d866c06
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.17
|
Security for flask-super-macros 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.