defer import tag & improved reconstructImage#333
Merged
Conversation
added 6 commits
May 24, 2019 16:09
pfarrel
approved these changes
May 30, 2019
pfarrel
left a comment
Contributor
There was a problem hiding this comment.
Looks good.
It might be nice to add a comment to the deferred login in ImportTag to explain a bit what's going on. It makes sense to me now, but I'm sure it could be surprising to someone who wasn't familiar with those features.
added 2 commits
May 30, 2019 15:27
Codecov Report
@@ Coverage Diff @@
## master #333 +/- ##
============================================
+ Coverage 71.54% 71.63% +0.09%
- Complexity 1580 1588 +8
============================================
Files 239 239
Lines 4965 4974 +9
Branches 805 807 +2
============================================
+ Hits 3552 3563 +11
+ Misses 1126 1125 -1
+ Partials 287 286 -1
Continue to review full report at Codecov.
|
boulter
approved these changes
May 30, 2019
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
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.
Defer import tag
This change handles the case where an import tag depends on deferred values. In this case the nodes inside of the tags will be added to the deferredNodes list and all created values inside of the SetTag will be deferred.
Assuming the file
my_properties.htmldepends on a deferred value.Example 1:
{% import 'custom/page/web_page_basic/my_properties.html' as header_footer %}header_footerwill be deferredExample 2:
{% import 'custom/page/web_page_basic/my_properties.html' %}All variables defined (or deferred) inside of the file will be deferred.
After that a DeferredValueException is thrown from inside of the
ImportTagin order to avoid rendering it and to reconstruct it properly.Improved reconstructImage
This change adds reconstructImage as a public function on the Node base class. This allows the child classes of Node to implement this function, however it will default to
master.getImage()so that users are not forced to implement it when they extend Node. This wayreconstructImagecan be improved inside ofTagNodeto reconstruct recursively. Before it would only reconstruct at the depth of 1.Example (from a test added in
DeferredTest):{% if deferred %}{% if resolved %}{{resolved}}{% endif %}{% else %}b{% endif %}Before the change this would have been reconstructed to
{% if deferred %}{% if resolved %}{% else %}b{% endif %}After the change it reconstructs correctly to the original template.
Considerations
At the moment, macros that are called with/depend on deferred values are not preserved correctly. At the time of rendering the macro definition, it's not possible right now to know if the value it depends on will be defined when the macro is actually called. This is not trivial and I'll need to think more about how to make it work well, but in order to move forward and make progress we've decided to not support this for the time being.
Also I'm aware of the
FromTag, which is very similar to theImportTag. I'll add DeferredValue support for it later.