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"
    }
  }
}

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flask_super_macros-0.2.0.tar.gz (2.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flask_super_macros-0.2.0-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

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

Hashes for flask_super_macros-0.2.0.tar.gz
Algorithm Hash digest
SHA256 0e93591823ee0ee25716f9b4f6a07bb2586f1ef1b697fdbde52d96d44362d1fc
MD5 bbce0c8b908477b87801ca94bf7a3965
BLAKE2b-256 845d79ce3dbee3ef7d01389ba9caf053d3ee64b3ae6ad8402896368e38f1b3d9

See more details on using hashes here.

File details

Details for the file flask_super_macros-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for flask_super_macros-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dd0e95e424862e3016ebdc4347ef9d23f37bdd1e95a1ca6dbacefeb39fb18b0a
MD5 4101deb0128ae3ec398a9d579ba086c7
BLAKE2b-256 89640bfd0a639f756ecae22e0cfd385573e519fd9100a92a3627cfa74d866c06

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page