Super charged Jinja macros for Flask
Project description
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"
}
}
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flask_super_macros-0.2.0.tar.gz.
File metadata
- Download URL: flask_super_macros-0.2.0.tar.gz
- Upload date:
- Size: 2.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e93591823ee0ee25716f9b4f6a07bb2586f1ef1b697fdbde52d96d44362d1fc
|
|
| MD5 |
bbce0c8b908477b87801ca94bf7a3965
|
|
| BLAKE2b-256 |
845d79ce3dbee3ef7d01389ba9caf053d3ee64b3ae6ad8402896368e38f1b3d9
|
File details
Details for the file flask_super_macros-0.2.0-py3-none-any.whl.
File metadata
- Download URL: flask_super_macros-0.2.0-py3-none-any.whl
- Upload date:
- Size: 3.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd0e95e424862e3016ebdc4347ef9d23f37bdd1e95a1ca6dbacefeb39fb18b0a
|
|
| MD5 |
4101deb0128ae3ec398a9d579ba086c7
|
|
| BLAKE2b-256 |
89640bfd0a639f756ecae22e0cfd385573e519fd9100a92a3627cfa74d866c06
|