]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
Add support for `{% from with context %}`
authorKevin <kevin@kevin-brown.com>
Tue, 12 May 2020 02:32:43 +0000 (22:32 -0400)
committerKevin <kevin@kevin-brown.com>
Tue, 12 May 2020 02:47:58 +0000 (22:47 -0400)
new_parser.py
test_template.jinja

index 6275b60c5b7544d46bb759d8a3c79fa14a2483a0..88cd4a62fea866d6c26c67102e89f7725c916726 100644 (file)
@@ -178,7 +178,12 @@ def parse_block_from(ast):
 \r
     template = parse_variable(parameters[0]['value'])\r
     names = []\r
-    with_context = False\r
+    with_context = _parse_import_context(parameters)\r
+\r
+    if with_context is None:\r
+        with_context = False\r
+    else:\r
+        del parameters[-2:]\r
 \r
     if len(parameters) > 2:\r
         for parameter in parameters[2:]:\r
@@ -617,3 +622,12 @@ def parse_variable_tuple(ast, variable_context):
         variable_context,\r
         lineno=lineno_from_parseinfo(ast['parseinfo'])\r
     )\r
+\r
+def _parse_import_context(block_parameters):\r
+    if block_parameters[-1]['value']['variable'] != 'context':\r
+        return None\r
+\r
+    if block_parameters[-2]['value']['variable'] not in ['with', 'without']:\r
+        return None\r
+\r
+    return block_parameters[-2]['value']['variable'] == 'with'
\ No newline at end of file
index bb71fcc7f96975e47ddf82aeb1eb43406507b3c3..f1a76e3a49ea481035228e5671735eb21abe1a60 100644 (file)
@@ -70,4 +70,5 @@ across lines #}
 {{ 1 in [1, 2, 3] }}\r
 {{ foo is not bar }}\r
 {{ not (foo and bar) }}\r
-{{ foo not in bar }}
\ No newline at end of file
+{{ foo not in bar }}\r
+{% from 'forms.html' import input with context %}
\ No newline at end of file