Skip to content

Keep track of parent path for each block in order to resolve relative paths#359

Merged
liamrharwood merged 3 commits into
masterfrom
fix-relative-paths-in-blocks
Aug 15, 2019
Merged

Keep track of parent path for each block in order to resolve relative paths#359
liamrharwood merged 3 commits into
masterfrom
fix-relative-paths-in-blocks

Conversation

@liamrharwood

Copy link
Copy Markdown
Contributor

The way that block tags are resolved is somewhat separate from the rest of the rendering process. This means that the currentPathStack 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 optional parentPath. When each block is rendered, we push its parentPath onto the currentPathStack which can then be used in inner tags to resolve relative paths.

@liamrharwood liamrharwood requested a review from mattcoley August 13, 2019 13:32

@mattcoley mattcoley left a comment

Copy link
Copy Markdown
Collaborator

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.

@mattcoley mattcoley requested a review from boulter August 13, 2019 14:21
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());

Copy link
Copy Markdown
Contributor

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());

Copy link
Copy Markdown
Contributor

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 ()

@liamrharwood liamrharwood Aug 15, 2019

Copy link
Copy Markdown
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants