Skip to content

Commit

Permalink
Merge pull request #8 from jpsca/flask-assets
Browse files Browse the repository at this point in the history
Accept external jinja_env
  • Loading branch information
jpsca authored Feb 22, 2023
2 parents 11b9b2b + 094de9b commit 49b169b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
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 <[email protected]>"]
license = "MIT"
Expand Down
13 changes: 10 additions & 3 deletions src/jinjax/catalog.py
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 comments on commit 49b169b

Please sign in to comment.