This repository has been archived by the owner on Nov 16, 2020. It is now read-only.
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.
An attempt at implementing static extensions with import/export as per #33. This is my first time contributing code to Vapor so please review.
This PR adds two new
TemplateSyntax
types:TemplateExtend
andTemplateImport
.TemplateExtend
contains a path to a target template and a dictionary of exports (with type[String:[TemplateSyntax]]
), whileTemplateImport
contains a string identifier referencing the name of an export. These types are included in the AST created by theTemplateParser
, but they are replaced with their values by a newTemplateRenderer
helper method calledresolveExtensions
(so they should never make it toTemplateSerializer
).resolveExtensions
recursively traverses the AST. If it finds aTemplateExtend
, it loads the referenced file, runs it through theTemplateParser
, and substitutes it in place of the extend statement. It traverses the newly-loaded AST as well, keeping track of the extension's exports to substitute them in place ofTemplateImport
s.I also included a few test cases. I mocked the input ASTs in a slightly hacky way: I created template files on disk to avoid a file-not-found error, but used a parser that ignored the file contents and returned one of several hard-coded ASTs (using the filename as a selector).
I have not (yet) implemented following features alluded to in #33 or the Swift Forums pitch:
TemplateRaw
s