Edgewall Software

Changes between Version 1 and Version 2 of TracDev/JinjaChecker


Ignore:
Timestamp:
Jul 21, 2016, 1:24:57 PM (8 years ago)
Author:
Christian Boos
Comment:

restructure the page by adding an #Example section

Legend:

Unmodified
Added
Removed
Modified
  • TracDev/JinjaChecker

    v1 v2  
    55To help with that problem, we wrote the [source:cboos.git/contrib/jinjachecker.py contrib/jinjachecker.py] tool.
    66
     7It first analyzes the Jinja2 control structures, and tries to provide some helpful diagnostics in case of nesting or stylistic errors.
     8It also adds curly braces to the statements, so if you have an editor which can do matching of brace pairs, you can quickly spot the origin o a nesting problem.
     9
     10Finally, while the indentation of the statements is free in Jinja2 templates, being consistent with it also helps to ensure a proper nesting.
     11
     12== Example
     13
     14The command:
    715{{{
    816python contrib/jinjachecker.py trac/wiki/templates/jwiki_view.html
    917}}}
    1018
    11 It first analyzes the Jinja2 control structures, and tries to provide some helpful diagnostics in case of nesting or stylistic errors.
    12 It also adds curly braces to the statements, so if you have an editor which can do matching of brace pairs, you can quickly spot the origin o a nesting problem.
    13 
    14 Finally, while the indentation of the statements is free in Jinja2 templates, being consistent with it also helps to ensure a proper nesting.
     19outputs:
    1520{{{
    1621# -- Jinja2 check for 'trac/wiki/templates/jwiki_view.html'
     
    102107}}}
    103108
    104 As a second step, jinjachecker removes the Jinja2 markup and performs a validation of the document, using lxml.
     109and:
    105110{{{
    106111# -- HTML check for 'trac/wiki/templates/jwiki_view.html'
     
    149154# -- HTML OK
    150155}}}
     156
     157The second part of this output is only generated if you have [pypi:lxml] installed. If that's the case, after having checked the Jinja2 syntax nesting in a first step, the jinjachecker tool removes the Jinja2 markup and performs a validation of the document using lxml in a second step.