8000 Accept external jinja_env by jpsca · Pull Request #8 · jpsca/jinjax · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Accept external jinja_env #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "jinjax"
version = "0.21"
version = "0.22"
description = "Replace your HTML templates with Python server-Side components"
authors = ["Juan-Pablo Scaletti <juanpablo@jpscaletti.com>"]
license = "MIT"
Expand Down
13 changes: 10 additions & 3 deletions src/jinjax/catalog.py
8000
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pathlib import Path

import jinja2
from jinja2.environment import load_extensions
from markupsafe import Markup

from .component import Component
Expand Down Expand Up @@ -45,6 +46,7 @@ def __init__(
filters: "t.Optional[dict[str,t.Any]]" = None,
tests: "t.Optional[dict[str,t.Any]]" = None,
extensions: "t.Optional[list]" = None,
jinja_env: "t.Optional[jinja2.Environment]" = None,
root_url: str = DEFAULT_URL_ROOT,
file_ext: "TFileExt" = DEFAULT_EXTENSION,
) -> None:
Expand All @@ -57,16 +59,21 @@ def __init__(
root_url = root_url.strip().rstrip(SLASH)
self.root_url = f"{root_url}{SLASH}"

extensions = (extensions or []) + ["jinja2.ext.do", JinjaX]
jinja_env = jinja2.Environment(
extensions=extensions,
jinja_env = jinja_env or jinja2.Environment(
undefined=jinja2.StrictUndefined,
)

extensions = (extensions or []) + ["jinja2.ext.do", JinjaX]
jinja_env.extensions.update(load_extensions(jinja_env, extensions))

globals = globals or {}
globals["catalog"] = self
jinja_env.globals.update(globals)

jinja_env.filters.update(filters or {})

jinja_env.tests.update(tests or {})

jinja_env.extend(catalog=self)
self.jinja_env = jinja_env

Expand Down
0