Keep track of parent path for each block in order to resolve relative paths#359
Merged
Conversation
mattcoley
approved these changes
Aug 13, 2019
mattcoley
left a comment
Collaborator
There was a problem hiding this comment.
It took me some time to understand what was going on exactly but I think this approach looks good.
boulter
approved these changes
Aug 14, 2019
| if (!blockNames.contains(blockPlaceholder.getBlockName())) { | ||
| Collection<List<? extends Node>> blockChain = blocks.get(blockPlaceholder.getBlockName()); | ||
| List<? extends Node> block = Iterables.getFirst(blockChain, null); | ||
| Collection<BlockInfo> blockChain = blocks.get(blockPlaceholder.getBlockName()); |
Contributor
There was a problem hiding this comment.
woo hoo, we're on the blockchain! Let's mine some bitcoin!
|
|
||
| blockValueBuilder.addNode(child.render(this)); | ||
|
|
||
| block.getParentPath().ifPresent(path -> getContext().getCurrentPathStack().pop()); |
Contributor
There was a problem hiding this comment.
nit: path is unused, can be replaced with ()
Contributor
Author
There was a problem hiding this comment.
I'm getting a compile error if I do that: Cannot infer functional interface type
I think it's because ifPresent takes a Consumer.
This was referenced Aug 15, 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.
The way that
blocktags are resolved is somewhat separate from the rest of the rendering process. This means that thecurrentPathStackdoes not correctly reflect the origin file of a block tag at the time it is resolved.In order to support resolving relative paths within block tags, we need to keep track of the parent path for each block. This PR adds a new
BlockInfoobject which holds both the list of nodes that are already used to resolve block stubs, as well as an optionalparentPath. When each block is rendered, we push itsparentPathonto thecurrentPathStackwhich can then be used in inner tags to resolve relative paths.