Skip to content
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 eager deferred macro logic #547

Merged
merged 12 commits into from
Nov 30, 2020
Merged

Add eager deferred macro logic #547

merged 12 commits into from
Nov 30, 2020

Conversation

jasmith-hs
Copy link
Contributor

Part of #532

This PR unstubs the getNewlyDeferredFunctionImages() method in the EagerTagDecorator class by introducing an EagerMacroFunction wrapper class, which wraps the logic of a MacroFunction to be able to reconstruct a partially evaluated image of the macro function to output before a deferred call of the said macro function.

Since macro functions can either be called directly (when they are stored as a global macro function), or with an imported alias, such as {% import path as simple %} {{ simple.the_macro() }}, there needs to be a way to create a macro in this way. So I formalised this aliased macro importing by calling it a local macro, rather than a global macro (because it's only local to the alias). The MacroTag now allows for a macro function to be stored in such a way: {% macro parent_alias.macro_name() %}, which allows for global or local macro functions on the context to be re-output before they're called.


For example:

{% macro plus_one(val) %}
{{ val + 1 }}
{% endmacro %}
{% import import_path as my_alias %}
{{ plus_one(deferred.age) }}
{% if my_alias.can_vote(deferred.age) %}
You can vote.
{% endif %}

Would result in an output similar to the following if doing eager execution (adjusted for readability):

{% macro plus_one(val) %}
{{ val + 1 }}
{% endmacro %}
{{ plus_one(deferred.age) }}
{% set my_alias = {} %}
{% macro my_alias.can_vote(val) %}
{{ val >= 18 }}
{% endmacro %}
{% if my_alias.can_vote(deferred.age) %}
You can vote.
{% endif %}

cc @boulter @Joeoh

Base automatically changed from eager-tag-decorator-no-macros to master November 30, 2020 18:45
@jasmith-hs jasmith-hs merged commit d21f61f into master Nov 30, 2020
@jasmith-hs jasmith-hs deleted the eager-tag-decorator-full branch November 30, 2020 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants