From 209b32cfdae122ed0ca516d5c94a2ad91d616e1f Mon Sep 17 00:00:00 2001 From: octo-gone Date: Thu, 8 Aug 2024 23:33:41 +0300 Subject: [PATCH] feat: render template when instantiating --- .github/workflows/publish.yml | 6 ---- .github/workflows/release.yml | 6 ---- README.md | 57 ++++++++++++++++++++++++++++++ pyproject.toml | 2 +- src/jinja2_components/component.py | 4 +++ src/jinja2_components/ext.py | 3 +- 6 files changed, 63 insertions(+), 15 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index cae6ea3..b0ebd17 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -18,12 +18,6 @@ jobs: uses: actions/setup-python@v5 with: python-version: '3.11' - - name: Cache Poetry - id: cache-poetry - uses: actions/cache@v4 - with: - path: ~/.poetry - key: poetry - name: Install Poetry if: steps.cache-poetry.outputs.cache-hit != 'true' run: | diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d7a65aa..5e9e6a7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,12 +18,6 @@ jobs: uses: actions/setup-python@v5 with: python-version: '3.11' - - name: Cache Poetry - id: cache-poetry - uses: actions/cache@v4 - with: - path: ~/.poetry - key: poetry - name: Install Poetry if: steps.cache-poetry.outputs.cache-hit != 'true' run: | diff --git a/README.md b/README.md index 4cf9ebf..8c3d65b 100644 --- a/README.md +++ b/README.md @@ -131,3 +131,60 @@ print(template.render()) # # ``` + +### Rendering component from code + +The idea behind this feature is to pass arguments and get rendered component inside the code. + +```python +@register(name="button") +class Button(Component): + template_str = "" + +@register(name="menu") +class Menu(Component): + template_str = """\ +