-
Notifications
You must be signed in to change notification settings - Fork 1
Add Jinja2 support #170
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
base: main
Are you sure you want to change the base?
Add Jinja2 support #170
Conversation
bump |
Hm not sure where I land on this. Though I do know I don't like including it as default, as it should be opt-in, so I agree with you there. I don't mind including it as the extra and having user's be able to install via Then again, we'll need to specify jinja as a dep anyway for the tests to run, so maybe there's no harm in just putting it as an extra as you've done.
The nested nature of it doesn't bother me, but the fact that there's nothing else in that module other than that file does. 😄 I'm okay with top-level file at
Honestly, probably not much more than that? You could copy the approach of the existing Django template tag tests here django-simple-nav/tests/test_templatetags.py Lines 18 to 90 in 4fa25a2
|
tests/test_jinja.py
Outdated
from .jinja2.environment import environment | ||
|
||
|
||
def test_derp(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LOL, but definitely change the name, if nothing else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me, but I've only ever been a consumer of Jinja templates through other means -- I'm ignorant when it comes to custom tags over there.
The tests mirror the Django template tag tests
for more information, see https://pre-commit.ci
Django was looking for a Jinja template in the Django template directory because the `DIR` value was kept.
for more information, see https://pre-commit.ci
I have now added tests which mirror There is one unfortunate name collision I encountered: a nav item has the field
This would try to iterate over the
I expect this will trip up quite a few Jinja users. How about renaming |
I have moved the implementation file to a more reasonable location and added documentation for Jinja. I am hereby done and wish to request a full review. |
Resolves #165. I have added the Jinja equivalent of the
django_simple_nav
template. In Jinja we can make a regular Python function available as a global variable in the Jinja environment, so the code is much simpler. The user will have to add the function to his own global environment when configuring Jinja in his project. The new function can be called like this:{{ django_simple_nav('my_app.navigation.SiteNav', 'my_app/main-nav.html.j2' }}
.I have some open questions though:
django_simple_nav.jinja2.django_simple_nav
. This looks too deeply nested to me, how aboutdjango_simple_nav.jinja2
instead?