-
Notifications
You must be signed in to change notification settings - Fork 170
Add basic deferred value support for from tag #381
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
Merged
Merged
+1,115
−89
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
boulter
approved these changes
Dec 13, 2019
mattcoley
approved these changes
Dec 13, 2019
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…ue & MacroFunction
Changes DefaultFilter to implement AdvancedFilter
adds PyList support to ForTag
@jboulter We have added some changes here to allow us to reconstruct macros. We also fixed a bug with the reconstructEndTags that it does not respect trim tags. |
… functions and expressions (#385) * Start implementing safe filter * Remove comment about pass-through implementation * Return var if it's not instance of string instead of throwing * Add test for pass-through * Add support for SafeString to all filters which handle Strings * Remove utils for string reverse filter * Handle SafeString in truncate function * Formatting fix * Add SafeStringFilter interface * Handle safe strings in filters * rm trailing space * Formatting fixes * Move safeFilter method to Filter IF and remove SafeFilter IF * rm space * Change behaviour of Urlize filter to not always return a SafeString * Code style changes * Remove unnecessary call to safeString * Style fix * Add tests to handle Urlize string being escaped and made safe * rm hardcoded string * rm uneeded getValue * Add SafeString type as str * Handle SafeString in expressions Co-authored-by: Joe <Joeoh@users.noreply.github.com>
* Fix line numbers * add to some more places * two levels deep test * Fix case with child interpreter * Add deprecation * Add another test * Update error messages * Fix up error messages and tests * Fix case with scopes * Add check for inherit * Put everything on the path stack * always push parent * remove callstack crud * Set back path management * Fix extend lineNo/position and keep track for each block * cleanup * Add test for extends * Add more tests * Check parent call stack for emtpy and line numbers * Fix test * Reorient line numbers when evaluating macros, make sure to pop import path off of stack * Add test for imported macros * Reorient line numbers when resolving blocks * Reorient line numbers when processing extend parents * Add tests for extends + includes
Revert "Implement safe filter as SafeString and handle SafeString in filters, functions and expressions"
… functions and expressions (#394) * Start implementing safe filter * Remove comment about pass-through implementation * Return var if it's not instance of string instead of throwing * Add test for pass-through * Handle safestrings and call implementor * Add tests * Handle SafeString in filter using kwargs * Handle safe strings in most simple expressions * Handle SafeString in IsUpperExp * Handle SafeString in filters. Allow overriding from within filter * Formatting fixes Co-authored-by: jkollmann <48923512+jkollmann@users.noreply.github.com>
…ue & MacroFunction
mattcoley
added a commit
that referenced
this pull request
Feb 11, 2020
This reverts commit e031909.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a follow up to #333
Defer from tag
Similar to ImportTag, FromTag imports can depend on deferred values. If this is the case we want to defer the whole import. The logic for imported properties is the same, we'll defer them so that all of the following code that depends on the import will not be rendered.
Example 1:
{% from 'custom/page/web_page_basic/my_properties.html' import header_footer %}
➡️
header_footer
will be deferredExample 1:
{% from 'custom/page/web_page_basic/my_properties.html' import header_footer as footer %}
➡️
footer
will be deferredAfter that a DeferredValueException is thrown from inside of the FromTag in order to avoid rendering it and to reconstruct it properly.
Defer macros
In case a
FromTag
/ImportTag
is deferred, we want to defer all calls to imported macros. Since the execution is not a property lookup we need a different way of handling it, we can't just put an instance of aDeferredValue
into the context.I decided to add
setDeferred(boolean deferred)
toMacroFunction
to allow us to mark them asdeferred
. This way, whenAstMacroFunction
is invoked we can throw theDeferredValueException
in order to prevent the wrapping tag from being rendered.Example:
Assuming the property
padding
is deferred, consider this macro definition:Before this change, the macro definition would have been deferred, however the call to the function would have rendered to
""
since theMacroFunction
is undefined un the context.With this PR the
spacer
MacroFunction will still be put into the context but it will have setisDeferred()
totrue
.So when
spacer
is called like this{{ spacer() }}
, the invocation will throw inside ofAstMacroFunction
andExpressionNode
will reconstruct the image.Additional Notes
I added another
to
JinjavaInterpreterResolver
to make it possible to defer nested properties. Before it was only possible to defer the "root".I updated
DeferredValue
to be able to hold it's original value. This is necessary in case that a deferred value is set to something different, otherwise we'd lose its state.