-
Notifications
You must be signed in to change notification settings - Fork 171
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
Keep track of parent path for each block in order to resolve relative paths #359
Conversation
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.
It took me some time to understand what was going on exactly but I think this approach looks good.
@@ -282,17 +283,22 @@ private void resolveBlockStubs(OutputList output, Stack<String> blockNames) { | |||
for (BlockPlaceholderOutputNode blockPlaceholder : output.getBlocks()) { | |||
|
|||
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()); |
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.
woo hoo, we're on the blockchain! Let's mine some bitcoin!
blockValueBuilder.addNode(child.render(this)); | ||
|
||
block.getParentPath().ifPresent(path -> getContext().getCurrentPathStack().pop()); |
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.
nit: path is unused, can be replaced with ()
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.
I'm getting a compile error if I do that: Cannot infer functional interface type
I think it's because ifPresent
takes a Consumer
.
The way that
block
tags are resolved is somewhat separate from the rest of the rendering process. This means that thecurrentPathStack
does 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
BlockInfo
object 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 itsparentPath
onto thecurrentPathStack
which can then be used in inner tags to resolve relative paths.