Custom template methods
Opened this issue · 2 comments
As we expand on our usage of mockintosh we need the ability to provide custom template methods to do more complicated actions. For instance, we have a use-case where we want to inject certain complicated structures into objects based on some conditions.
FWIW we are using the docker container and happy to build out new python methods. We just need an easy way to wire them into Mockintosh. At the moment we are mounting copies of the hbs/methods.py
and templating.py
files into the container with custom code.
I have limited python knowledge but i think something like the following could be useful.
- Mockintosh uses something to determine where to read custom methods.
a. An env var to define where custom methods files will be read.MOCKINTOSH_TEMPLATE_METHODS_DIR
.
b. OR additional yaml configuration that specifies either a directory or specific files to load? - Place the file with custom methods at that ^^ location.
- Each methods file will expose an
inject_methods() -> list[Callable]
method. These defined methods can be merged with the existing methods in thetemplating.py
file.
Have you looked at the interceptors (https://mockintosh.io/#interceptors) ?
This is, in a way, related to #164. Giving users of the service the ability to inject new template methods would be a large usability boon as they could be iterated upon within the UI editor, etc. (Their usage, I mean. The implementation could be unit tested elsewhere if needed)
I did not see interceptors previously. Good to know they exist but they feel too general for this use-case. Interceptors seem to lack the interactivity you get from editing config/templates/etc. through the UI.