apryor6 / flaskerize

Python CLI build/dev tool for templated code generation and project modification. Think Angular schematics for Python.
BSD 3-Clause "New" or "Revised" License
121 stars 13 forks source link

Support package-level custom Jinja template functions #16

Closed apryor6 closed 4 years ago

apryor6 commented 5 years ago

Currently, schematics may provide custom functions for use within the context of that schematic by providing a custom_functions.py file that includes functions decorated with register_custom_function; however, in cases where many schematics exist within one large project it would be preferable to have a single place to expose functions within the scope of all child schematics.

A possible solution would be to recursively search for any/all occurrences of custom_functions.py when resolving the full schematic path and to then apply them sequentially. The order here should matter -- highest priority shall be given to the most granular scope (i.e. if an identically-named function is provided at the schematic-level custom_functions.py it should override the global. This is relatively easy to implement by parsing the most-specific file last, which would override the colliding keys within env.globals for the Jinja environment.

apryor6 commented 4 years ago

This has been implemented here, and I forgot to link to the issue.