-
Notifications
You must be signed in to change notification settings - Fork 169
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
defer variables containing deferred vals & track deferred nodes in context #327
Conversation
Codecov Report
@@ Coverage Diff @@
## master #327 +/- ##
============================================
+ Coverage 71.47% 71.49% +0.02%
- Complexity 1572 1575 +3
============================================
Files 239 239
Lines 4939 4954 +15
Branches 797 799 +2
============================================
+ Hits 3530 3542 +12
- Misses 1124 1126 +2
- Partials 285 286 +1
Continue to review full report at Codecov.
|
84be45e
to
e5db0b4
Compare
e5db0b4
to
43a36ab
Compare
interpreter.getContext().put(var, interpreter.resolveELExpression(expr, tagNode.getLineNumber())); | ||
} | ||
} catch (DeferredValueException e) { | ||
Stream.of(varTokens).forEach(varToken -> interpreter.getContext().put(varToken.trim(), DeferredValue.instance())); |
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.
This is the key bit that makes "deferred-ness" infectious, for any other readers trying to see what actually changed through the whitespace diff.
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.
Looks good
2a99110
to
4cc4a12
Compare
Following #282
It's possible that variables contain deferred values, in that case the assigned variable(s) should be deferred too, since expressions depending on variables containing deferred values can't and shouldn't be evaluated & rendered.
Example:
Input:
Render before the change:
After the change:
We need some way of tracking which nodes were deferred so that we can escape them before post-processing the rendered template with Jsoup. If Jsoup encounters these kinds of tags in a place where no characters are allowed it changes the template and even ignores following tags inside of that tag.
Example:
Input:
Jsoup output:
In order to escape these tags properly we need to know which tags were deferred.
We also want to handle the case where a deferred tag contains not-deferred variables. We need to be able to take these out of the context later for further processing.
Example:
Input:
Output:
defined_var
disappears butsome_var
will not be rendered since it contains a deferred value. If we know which tags have been deferred after the render we can take the vars out of the context and pass them along for a second render.Considerations: I've tried a couple of different approaches, including partial evaluation and extracting variables of deferred tags. Both are a lot more complex than I initially thought and too specific to our use-case, especially given the fact that we don't own
ExpressionFactoryImpl
and all the code that this class depends on. IMO this is the most flexible solution, since users can decide what to do with the deferred nodes after rendering is done.