]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
Support filters on all variables
authorKevin <kevin@kevin-brown.com>
Sun, 10 May 2020 02:23:32 +0000 (22:23 -0400)
committerKevin <kevin@kevin-brown.com>
Sun, 10 May 2020 02:23:32 +0000 (22:23 -0400)
This adds support to filters on all variables instead of to just
variables which are being printed within templates. This now allows
us to pass in variables that are using filters as parameters within
a block, so they can be used for setting new variables or to perform
transformations on the fly.

.gitignore
grammar.ebnf
test_tatsu.py
test_template.jinja

index 81752e0e9eb797e860ae41074c9a8ff1f1b58881..dacb502c82abd2b1a0ce4a3683845f47985a6a70 100644 (file)
@@ -18,3 +18,4 @@ venv-*/
 htmlcov
 .pytest_cache/
 /.vscode/
+tatsu_test.json
\ No newline at end of file
index 667e8100fdafa1478c9125e9c7456ca0fa8edfbc..314e9341c813680a667d543f0c4ca9ab47ba8549 100644 (file)
@@ -126,7 +126,7 @@ block_parameter_value_only
 \r
 variable_expression\r
     =\r
-    variable_open type:`variable` name:variable_identifier { !variable_close {SP}* filters+:variable_filter }* variable_close\r
+    variable_open type:`variable` name:variable_identifier variable_close\r
     ;\r
 variable_open\r
     =\r
@@ -141,6 +141,7 @@ variable_identifier
     =\r
     variable:( LITERAL | IDENTIFIER )\r
     accessors:{ variable_accessor }*\r
+    { {SP}* filters+:variable_filter }*\r
     ;\r
 \r
 variable_accessor\r
index d197f550c62301cd6d6a05c0fac948651d75b1da..8ff2e45b1685cea4d9f9d6276a7e58e9883e84cc 100644 (file)
@@ -1,7 +1,8 @@
+from datetime import datetime\r
 from tatsu.util import asjson\r
 import json\r
 import tatsu\r
-from datetime import datetime\r
+import sys\r
 \r
 \r
 with open('grammar.ebnf', 'r') as tatsu_grammar:\r
@@ -20,5 +21,5 @@ with open('grammar.ebnf', 'r') as tatsu_grammar:
 \r
         print(json.dumps(asjson(ast), indent=2))\r
 \r
-        print("Grammar", grammar_end - grammar_start)\r
-        print("Parser", parse_end - parse_start)
\ No newline at end of file
+        print("Grammar", grammar_end - grammar_start, file=sys.stderr)\r
+        print("Parser", parse_end - parse_start, file=sys.stderr)
\ No newline at end of file
index 6d8129ca0f81dcc1d0697e52823bc56691863e8a..af50f6503d2951e4a56a5cb04d85aa5889029a02 100644 (file)
@@ -41,4 +41,8 @@ across lines #}
     # for item in seq:\r
     <li>{{ item }}</li>     ## this comment is ignored\r
     # endfor\r
-</ul>
\ No newline at end of file
+</ul>\r
+{% set reply | wordwrap %}\r
+    You wrote:\r
+    {{ message }}\r
+{% endset %}
\ No newline at end of file