Skip to main content

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 macro directive in all template files called __macros__.html
  • Created from files with the extension .macro.html
  • Created from files in the macros folder

(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)

Source distribution for flask-super-macros 0.2.0
File Size Uploaded
flask_super_macros-0.2.0.tar.gz 2.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for flask-super-macros 0.2.0
File Interpreter ABI Platform
flask_super_macros-0.2.0-py3-none-any.whl Python 3 none any Details

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

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page