ykmnkmi / jinja.dart

Jinja2 template engine port for Dart.
https://pub.dev/packages/jinja
MIT License
51 stars 11 forks source link

Added passContext for Functions #22

Closed vsheffer closed 2 years ago

vsheffer commented 2 years ago

In order to emulate macros I've added the ability to passContext to global functions. I'm not sure if this is in line with your future intentions for macros but this ability will allow my team to replace our current Python Jinaja2 macros with what we already have with no changes to the templates.

vsheffer commented 2 years ago

I have not handled the case of passing the environment so this may not be complete. If I need to add that please let me know.

ykmnkmi commented 2 years ago

I'm now thinking about removing environment.callFilter, environment.callTest, context.call check and writing an AST modifier that looks into the Environment.passArrgument and modifies AST from contextFunction(argument) to contextFunction(contextRef, argument).

ykmnkmi commented 2 years ago

Thanks for PR, can you add environment case and new line before second var and around if block?

ykmnkmi commented 2 years ago

Thanks.