Repository navigation
Add Tera::get_referenced_templates - #1059
Open
patrick-immometrica wants to merge 1 commit into
Open
patrick-immometrica wants to merge 1 commit into
patrick-immometrica wants to merge 1 commit into
Conversation
Returns the templates a template references through extends and include, including the ones referenced by those templates, for dependency tracking. Closes Keats#1044
This branch has not been deployed
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.
Closes #1044
Adds
Tera::get_referenced_templates(name). It returns the names of the templates a template references throughextendsandinclude, plus the ones those templates reference in turn. It sits next toget_template_variablesand works the same way.I went with the full set of templates instead of only the direct references that
jinja2.meta.find_referenced_templatesreturns. For dependency tracking you want to know thatpage.htmldepends onnav.htmlwhenbase.htmlis the template that includes it. Tera already resolves the parent chain, so this is a short walk overparentsandinclude_calls.Differences from the Jinja function:
Noneentries. Tera only accepts string literals inextendsandinclude, so every name is known.Like
get_template_variables, it reports every reference it finds, including ones inside anifor inside a block that a child overrides. It also reports the parent of an included template that usesextends. I'd rather over-report than have a site generator skip a rebuild it needed.I added a test in
tests/introspection.rsthat covers an extends chain with includes at each level, nested includes, a fallback prefix, an included template that extends another one, a template with no references, and an unknown template name.