-
Notifications
You must be signed in to change notification settings - Fork 5
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
Custom Filter for Jinja Renderer #9
Comments
Hi Suhendi. Custom filters certainly make sense, even outside of this use case. It could be perhaps implemented as new command line option, pointing to a Python file that contains custom filter functions? And use the function names as the filter names. For example:
where from typing import Type, List, Iterable
def class_title(cls: Type) -> str:
return cls.Config.title if hasattr(getattr(cls, 'Config', None), 'title') else cls.__name__
def sort_title(iterable: Iterable) -> List:
return list(sorted(iterable, key=class_title)) |
Thanks for your feedback. I will get started with a draft of sort. On the topic of expanding the jinja functionality, I am thinking that maybe we can instead create some sort of hooks that passes the jinja Something along the line of the following: where
This way we can extend some of the functionality such as creating a hook for preprocessing the |
That's also a good idea 👍 It is likely more attributes of the |
Hello @radeklat , thanks for the last update to expose classes. So far, I am enjoying my experience in auto generating configurations for my apps :D.
Currently I am contemplating the solution for one of my use cases. I want to display the class title and render each classes sorted by their titles. I displayed the title by using the following macro:
However, I reached a conundrum while trying to sort the classes by their title. After some tinkering, I figured out a way to achieve this is to add custom filters. So I modified the
main.py
(for testing purpose):And I use them in the following way:
I am wondering what are your thoughts on this and if it is worth supporting custom filters without having to modify the
main.py
. I will gladly write a pull request if you think that this is a good idea/feature to support.The text was updated successfully, but these errors were encountered: