Skip to content
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

collected_js and collected_css are not reset when rendering new jinja templates #89

Closed
ikus060 opened this issue Aug 22, 2024 · 3 comments

Comments

@ikus060
Copy link

ikus060 commented Aug 22, 2024

Hello,

I'm having issued with JinjaX collected list of javascript and css.

Creating a small snippet to reproduce the problem is not that easy, but here is a pseudo code of the problem:

env = jinja2.Environment(
    loader=jinja2.PackageLoader('udb'),
    auto_reload=True,
    autoescape=True,
    trim_blocks=True,
    lstrip_blocks=True,
    extensions=['jinja2.ext.i18n'],
)
env.add_extension(jinjax.JinjaX)
catalog = jinjax.Catalog(jinja_env=env, root_url="/static/")
catalog.add_folder(resource_filename('udb', 'templates/components'))

# Generating first template
env.get_template('templates1.html').render()

# Generating second templates
env.get_template('templates2.html').render()
# Issue : Ouput of this command include all the javascript and css collected so far. That include javascript and css from templates1.
# Expected behavior: I'm expecting calls to render() to reset the list of collected javascript and css to only include those required for templates2

Possible I'm using the library the wrong way. So don't hesitate to correct me.

Thanks

@jpsca
Copy link
Owner

jpsca commented Aug 22, 2024

JinjaX is not meant to be used like that, would this work for you?

env = jinja2.Environment(
    loader=jinja2.PackageLoader('udb'),
    auto_reload=True,
    autoescape=True,
    trim_blocks=True,
    lstrip_blocks=True,
    extensions=['jinja2.ext.i18n'],
)
catalog = jinjax.Catalog(jinja_env=env, root_url="/static/")
catalog.add_folder(resource_filename('udb', 'templates/components'))

html1 = catalog.render("templates1")
# ...
html2 = catalog.render("templates2")

@jpsca jpsca closed this as completed Aug 23, 2024
@ikus060
Copy link
Author

ikus060 commented Aug 26, 2024

I have issue with this approach because the framework I'm using required a jinja_env to work with. Not a Catalog.

Also, not all my templates are define (or converted to components) yet. To my knowledge, calling catalog.render("templates1") will only work with components. So this is causing me issue as I want to render Jinja templates that include JinjaX components.

That also make me wonder, are collected_css and collected_js thread safe ? I don't think so.

@jpsca
Copy link
Owner

jpsca commented Aug 29, 2024

They were not thread safe.
Now they are: #90

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants