Skip to content
Myr

rename default branch in files

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Lord · committed by David Lord · parent e7dce0b · Browse files · 7 files+59 added−56 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

7 files+59 added−56 removed

  • tests:+47 added−44 removed
  • other:+12 added−12 removed

7 files+59 added−56 removed

modified:.github/workflows/tests.yaml+2 added-2 removed
modified:docs/templates.rst+2 added-2 removed
425 unmodified lines
426this template "extends" another template. When the template system evaluates427this template, it first locates the parent. The extends tag should be the428first tag in the template. Everything before it is printed out normally and429may cause confusion. For details about this behavior and how to take430advantage of it, see :ref:`null-master-fallback`. Also a block will always be430advantage of it, see :ref:`null-default-fallback`. Also a block will always be431filled in regardless of whether the surrounding condition is evaluated to be true432or false.433434The filename of the template depends on the template loader. For example, the
994 unmodified lines
1429It is also possible to use inline `if` expressions. These are useful in some1430situations. For example, you can use this to extend from one template if a1431variable is defined, otherwise from the default layout template::14321433 {% extends layout_template if layout_template is defined else 'master.html' %}1433 {% extends layout_template if layout_template is defined else 'default.html' %}14341435The general syntax is ``<do something> if <something is true> else <do1436something else>``.1437
451 unmodified lines
modified:docs/tricks.rst+4 added-4 removed
5 unmodified lines
6This part of the documentation shows some tips and tricks for Jinja7templates.8910.. _null-master-fallback:10.. _null-default-fallback:1112Null-Master Fallback13--------------------12Null-Default Fallback13---------------------1415Jinja supports dynamic inheritance and does not distinguish between parent16and child template as long as no `extends` tag is visited. While this leads17to the surprising behavior that everything before the first `extends` tag
6 unmodified lines
24to false which it does per default if it's not defined. Additionally a very25basic skeleton is added to the file so that if it's indeed rendered with26`standalone` set to `True` a very basic HTML skeleton is added::2728 {% if not standalone %}{% extends 'master.html' %}{% endif -%}28 {% if not standalone %}{% extends 'default.html' %}{% endif -%}29 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">30 <title>{% block title %}The Page Title{% endblock %}</title>31 <link rel="stylesheet" href="style.css" type="text/css">32 {% block body %}
68 unmodified lines
modified:examples/basic/test.py+2 added-2 removed
3 unmodified lines
4env = Environment(5 loader=DictLoader(6 {7 "child.html": """\8{% extends master_layout or 'master.html' %}8{% extends default_layout or 'default.html' %}9{% include helpers = 'helpers.html' %}10{% macro get_the_answer() %}42{% endmacro %}11{% title = 'Hello World' %}12{% block body %}13 {{ get_the_answer() }}14 {{ helpers.conspirate() }}15{% endblock %}16""",17 "master.html": """\17 "default.html": """\18<!doctype html>19<title>{{ title }}</title>20{% block body %}{% endblock %}21""",
8 unmodified lines
modified:tests/test_ext.py+4 added-4 removed
16 unmodified lines
17_gettext_re = re.compile(r"_\((.*?)\)", re.DOTALL)181920i18n_templates = {21 "master.html": '<title>{{ page_title|default(_("missing")) }}</title>'21 "default.html": '<title>{{ page_title|default(_("missing")) }}</title>'22 "{% block body %}{% endblock %}",23 "child.html": '{% extends "master.html" %}{% block body %}'23 "child.html": '{% extends "default.html" %}{% block body %}'24 "{% trans %}watch out{% endtrans %}{% endblock %}",25 "plural.html": "{% trans user_count %}One user online{% pluralize %}"26 "{{ user_count }} users online{% endtrans %}",27 "plural2.html": "{% trans user_count=get_user_count() %}{{ user_count }}s"
1 unmodified line
29 "stringformat.html": '{{ _("User: %(num)s")|format(num=user_count) }}',30}3132newstyle_i18n_templates = {33 "master.html": '<title>{{ page_title|default(_("missing")) }}</title>'33 "default.html": '<title>{{ page_title|default(_("missing")) }}</title>'34 "{% block body %}{% endblock %}",35 "child.html": '{% extends "master.html" %}{% block body %}'35 "child.html": '{% extends "default.html" %}{% block body %}'36 "{% trans %}watch out{% endtrans %}{% endblock %}",37 "plural.html": "{% trans user_count %}One user online{% pluralize %}"38 "{{ user_count }} users online{% endtrans %}",39 "stringformat.html": '{{ _("User: %(num)s", num=user_count) }}',
675 unmodified lines
modified:tests/test_inheritance.py+43 added-40 removed
147 unmodified lines
148 def test_dynamic_inheritance(self, env):149 env = Environment(150 loader=DictLoader(151 {152 "master1": "MASTER1{% block x %}{% endblock %}",153 "master2": "MASTER2{% block x %}{% endblock %}",154 "child": "{% extends master %}{% block x %}CHILD{% endblock %}",152 "default1": "DEFAULT1{% block x %}{% endblock %}",153 "default2": "DEFAULT2{% block x %}{% endblock %}",154 "child": "{% extends default %}{% block x %}CHILD{% endblock %}",155 }156 )157 )158 tmpl = env.get_template("child")159 for m in range(1, 3):160 assert tmpl.render(master=f"master{m}") == f"MASTER{m}CHILD"160 assert tmpl.render(default=f"default{m}") == f"DEFAULT{m}CHILD"161162 def test_multi_inheritance(self, env):163 env = Environment(164 loader=DictLoader(165 {166 "master1": "MASTER1{% block x %}{% endblock %}",167 "master2": "MASTER2{% block x %}{% endblock %}",168 "child": """{% if master %}{% extends master %}{% else %}{% extends169 'master1' %}{% endif %}{% block x %}CHILD{% endblock %}""",166 "default1": "DEFAULT1{% block x %}{% endblock %}",167 "default2": "DEFAULT2{% block x %}{% endblock %}",168 "child": (169 "{% if default %}{% extends default %}{% else %}"170 "{% extends 'default1' %}{% endif %}"171 "{% block x %}CHILD{% endblock %}"172 ),173 }174 )175 )176 tmpl = env.get_template("child")174 assert tmpl.render(master="master2") == "MASTER2CHILD"175 assert tmpl.render(master="master1") == "MASTER1CHILD"176 assert tmpl.render() == "MASTER1CHILD"177 assert tmpl.render(default="default2") == "DEFAULT2CHILD"178 assert tmpl.render(default="default1") == "DEFAULT1CHILD"179 assert tmpl.render() == "DEFAULT1CHILD"180181 def test_scoped_block(self, env):182 env = Environment(183 loader=DictLoader(184 {182 "master.html": "{% for item in seq %}[{% block item scoped %}"185 "default.html": "{% for item in seq %}[{% block item scoped %}"186 "{% endblock %}]{% endfor %}"187 }188 )189 )190 t = env.from_string(188 "{% extends 'master.html' %}{% block item %}{{ item }}{% endblock %}"191 "{% extends 'default.html' %}{% block item %}{{ item }}{% endblock %}"192 )193 assert t.render(seq=list(range(5))) == "[0][1][2][3][4]"194195 def test_super_in_scoped_block(self, env):196 env = Environment(197 loader=DictLoader(198 {196 "master.html": "{% for item in seq %}[{% block item scoped %}"199 "default.html": "{% for item in seq %}[{% block item scoped %}"200 "{{ item }}{% endblock %}]{% endfor %}"201 }202 )203 )204 t = env.from_string(202 '{% extends "master.html" %}{% block item %}'205 '{% extends "default.html" %}{% block item %}'206 "{{ super() }}|{{ item * 2 }}{% endblock %}"207 )208 assert t.render(seq=list(range(5))) == "[0|0][1|2][2|4][3|6][4|8]"209
27 unmodified lines
237 def test_level1_required(self, env):238 env = Environment(239 loader=DictLoader(240 {238 "master": "{% block x required %}{# comment #}\n {% endblock %}",239 "level1": "{% extends 'master' %}{% block x %}[1]{% endblock %}",241 "default": "{% block x required %}{# comment #}\n {% endblock %}",242 "level1": "{% extends 'default' %}{% block x %}[1]{% endblock %}",243 }244 )245 )246 rv = env.get_template("level1").render()
2 unmodified lines
249 def test_level2_required(self, env):250 env = Environment(251 loader=DictLoader(252 {250 "master": "{% block x required %}{% endblock %}",251 "level1": "{% extends 'master' %}{% block x %}[1]{% endblock %}",252 "level2": "{% extends 'master' %}{% block x %}[2]{% endblock %}",253 "default": "{% block x required %}{% endblock %}",254 "level1": "{% extends 'default' %}{% block x %}[1]{% endblock %}",255 "level2": "{% extends 'default' %}{% block x %}[2]{% endblock %}",256 }257 )258 )259 rv1 = env.get_template("level1").render()
5 unmodified lines
265 def test_level3_required(self, env):266 env = Environment(267 loader=DictLoader(268 {266 "master": "{% block x required %}{% endblock %}",267 "level1": "{% extends 'master' %}",269 "default": "{% block x required %}{% endblock %}",270 "level1": "{% extends 'default' %}",271 "level2": "{% extends 'level1' %}{% block x %}[2]{% endblock %}",272 "level3": "{% extends 'level2' %}",273 }274 )
11 unmodified lines
286 def test_invalid_required(self, env):287 env = Environment(288 loader=DictLoader(289 {287 "master": "{% block x required %}data {# #}{% endblock %}",288 "master1": "{% block x required %}{% block y %}"290 "default": "{% block x required %}data {# #}{% endblock %}",291 "default1": "{% block x required %}{% block y %}"292 "{% endblock %} {% endblock %}",290 "master2": "{% block x required %}{% if true %}"293 "default2": "{% block x required %}{% if true %}"294 "{% endif %} {% endblock %}",292 "level1": "{% if master %}{% extends master %}"293 "{% else %}{% extends 'master' %}{% endif %}"295 "level1": "{% if default %}{% extends default %}"296 "{% else %}{% extends 'default' %}{% endif %}"297 "{%- block x %}CHILD{% endblock %}",298 }299 )300 )
2 unmodified lines
303 with pytest.raises(304 TemplateSyntaxError,305 match="Required blocks can only contain comments or whitespace",306 ):304 assert t.render(master="master")305 assert t.render(master="master2")306 assert t.render(master="master3")307 assert t.render(default="default")308 assert t.render(default="default2")309 assert t.render(default="default3")310311 def test_required_with_scope(self, env):312 env = Environment(313 loader=DictLoader(314 {312 "master1": "{% for item in seq %}[{% block item scoped required %}"315 "default1": "{% for item in seq %}[{% block item scoped required %}"316 "{% endblock %}]{% endfor %}",314 "child1": "{% extends 'master1' %}{% block item %}"317 "child1": "{% extends 'default1' %}{% block item %}"318 "{{ item }}{% endblock %}",316 "master2": "{% for item in seq %}[{% block item required scoped %}"319 "default2": "{% for item in seq %}[{% block item required scoped %}"320 "{% endblock %}]{% endfor %}",318 "child2": "{% extends 'master2' %}{% block item %}"321 "child2": "{% extends 'default2' %}{% block item %}"322 "{{ item }}{% endblock %}",323 }324 )325 )
9 unmodified lines
335 def test_duplicate_required_or_scoped(self, env):336 env = Environment(337 loader=DictLoader(338 {336 "master1": "{% for item in seq %}[{% block item "339 "default1": "{% for item in seq %}[{% block item "340 "scoped scoped %}}{{% endblock %}}]{{% endfor %}}",338 "master2": "{% for item in seq %}[{% block item "341 "default2": "{% for item in seq %}[{% block item "342 "required required %}}{{% endblock %}}]{{% endfor %}}",340 "child": "{% if master %}{% extends master %}{% else %}"341 "{% extends 'master1' %}{% endif %}{%- block x %}"343 "child": "{% if default %}{% extends default %}{% else %}"344 "{% extends 'default1' %}{% endif %}{%- block x %}"345 "CHILD{% endblock %}",346 }347 )348 )349 tmpl = env.get_template("child")350 with pytest.raises(TemplateSyntaxError):348 tmpl.render(master="master1", seq=list(range(3)))349 tmpl.render(master="master2", seq=list(range(3)))351 tmpl.render(default="default1", seq=list(range(3)))352 tmpl.render(default="default2", seq=list(range(3)))353354355class TestBugFix:356 def test_fixed_macro_scoping_bug(self, env):
49 unmodified lines
modified:CONTRIBUTING.rst+2 added-2 removed
139 unmodified lines
140 $ git fetch origin141 $ git checkout -b your-branch-name origin/1.1.x142143 If you're submitting a feature addition or change, branch off of the144 "master" branch.144 "main" branch.145146 .. code-block:: text147148 $ git fetch origin149 $ git checkout -b your-branch-name origin/master149 $ git checkout -b your-branch-name origin/main150151- Using your favorite editor, make your changes,152 `committing as you go`_.153- Include tests that cover any code changes you make. Make sure the
63 unmodified lines