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.
This pull request adds
analyze_tags
,analyze_tags_async
andanalyze_tags_from_string
methods toliquid.Environment
. Each of these methods inspects tokens from template source text and returns an instance ofliquid.TagAnalysis
, without constructing an abstract syntax tree. This is useful for identifying unknown, misplaced and unbalanced tags before attempting to parse source text into aliquid.BoundTemplate
.Closes #95.
TagAnalysis
objects include several useful properties, each of which is a mapping of tag names to a list of(template_name, line_number)
tuples, one tuple for each occurrence of the tag.This example analyzes tags in
article.liquid
from the tribble test fixture.output
If a template's source text contains unbalanced block tags, those tags will appear in
TagAnalysis.unclosed_tags
.Tags that are not registered with the environment will appear in
TagAnalysis.unknown_tags
.If an "inner" tag - like
elsif
andelse
forif
andunless
tags - appear without an appropriate enclosing block, those tags will appear inTagAnalysis.unexpected_tags
.