-
-
Notifications
You must be signed in to change notification settings - Fork 14
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
Add jinja2 extensions #90
Comments
Perhaps we need some way to enable jinja extensions in the moban yaml. That way people can choose which ones they need. But enabling expression-statement and loop-controls by default seems sensible. Extra features for free. |
thanethomson/statik#6 shows jinja extensions being configurably added by a tool with a similar ethos. |
I was trying to solve the issue. The user adds the required extensions in the yaml or mobanfile, something like:
And I am passing the list of extensions through BaseEngine, i.e., |
The extensions are expression-statement and loop-controls Related to moremoban#90
I am going to enable this
|
@ayan-b can you help contribute some docs for extensions? for it to go out, as my personal convention, it needs some thing like this: My extensions work lives in |
Sure. However, as per #90 (comment) , we should have expression-statement and loopcontrol enabled by default. I can make a PR doing the same. What do you think? |
Related to moremoban#90
Related to moremoban#90
Can we have some docs showing / testing use with jinja2-time and https://github.com/duelafn/python-jinja2-apci |
@chfw as it turns out the corresponding package needs to be imported, for example, if we want to use from jinja2 import Environment
import jinja2_time
env = Environment(extensions=['jinja2_time.TimeExtension'])
env.datetime_format = '%a, %d %b %Y %H:%M:%S'
# Timezone 'utc', default format -> "Thu, 10 Dec 2015 15:49:01"
template = env.from_string("{% now 'utc' %}")
template.render()
|
I think jinja extensions could be part of the 'options' mapping. |
I also thought the same but that would be somewhat inefficient as per the current moban architecture since the extensions are always required to be included during environment initialization. So, in that case, the environment is needed to be initialized for each |
Any more change for this issue? Since we have already added extensions support. |
We need to dynamically import the extension, for example |
Dynamic import could be achieved easily. |
why jinja2_time should be imported whereas jinja2.ext.loop shall not? Is there a natural rule that we can code it up? |
Yup, for example, the extensions are: I am sending a PR related to this. |
since 0.6.2, |
practical usage of |
Here is the documentation on its usage inside mobanfile: https://moban.readthedocs.io/en/latest/level-12-use-template-engine-extensions/README.html |
since 0.8.2, the extended syntax below, will activate ad-hoc filter, test and global of your choice.
|
Especially helpful is statement support, aka
do
http://jinja.pocoo.org/docs/2.10/extensions/#expression-statement
Loop Controls would also be nice syntax to have available.
https://github.com/duelafn/python-jinja2-apci looks very helpful for debugging, and for intentionally breaking templates when backwards compatibility is not possible.
https://github.com/wewearglasses/jinja2-required-variables-extension looks great for performance improvements.
https://github.com/zehome/jinja2-commentif looks good for adding comments without the hash prefix which is a keyword in jinja2
https://github.com/tlatsas/jinja2-highlight would be great for documentation.
While very basic, it would also by good to add https://pypi.org/project/jinja2-git/ , and add new git based information to that extension.
Likewise https://pypi.org/project/jinja2-github/ and https://github.com/hackebrot/jinja2-time
https://github.com/stanfeldman/compressinja looks interesting.
https://github.com/danielchatfield/jinja2_markdown or https://github.com/nrsimha/jingo-markdown might be better as an optional moban extension.
https://github.com/jpscaletti/jinja-includewith is a nice syntax improvement
Note to self: see if https://github.com/mankyd/jinjatag is still usable.
The text was updated successfully, but these errors were encountered: