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
Provenance
- Commit
9b86bbc- Tree
bc68fbf- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
e7dce0b
7 files changed+59 added−56 removed
modified:.github/workflows/tests.yaml+2 added-2 removed
123455678910111213131415161743 unmodified linesname: Testson: push: branches: - master - main - '*.x' paths-ignore: - 'docs/**' - '*.md' - '*.rst' pull_request: branches: - master - main - '*.x' paths-ignore: - 'docs/**' - '*.md'43 unmodified linesmodified:docs/templates.rst+2 added-2 removed
425 unmodified lines426 this template "extends" another template. When the template system evaluates427 this template, it first locates the parent. The extends tag should be the428 first tag in the template. Everything before it is printed out normally and429 may cause confusion. For details about this behavior and how to take430-advantage of it, see :ref:`null-master-fallback`. Also a block will always be430+advantage of it, see :ref:`null-default-fallback`. Also a block will always be431 filled in regardless of whether the surrounding condition is evaluated to be true432 or false.433 434 The filename of the template depends on the template loader. For example, the994 unmodified lines1429 It is also possible to use inline `if` expressions. These are useful in some1430 situations. For example, you can use this to extend from one template if a1431 variable is defined, otherwise from the default layout template::1432 1433- {% extends layout_template if layout_template is defined else 'master.html' %}1433+ {% extends layout_template if layout_template is defined else 'default.html' %}1434 1435 The general syntax is ``<do something> if <something is true> else <do1436 something else>``.1437 451 unmodified linesmodified:docs/tricks.rst+4 added-4 removed
5 unmodified lines6 This part of the documentation shows some tips and tricks for Jinja7 templates.8 9 10-.. _null-master-fallback:10+.. _null-default-fallback:11 12-Null-Master Fallback13---------------------12+Null-Default Fallback13+---------------------14 15 Jinja supports dynamic inheritance and does not distinguish between parent16 and child template as long as no `extends` tag is visited. While this leads17 to the surprising behavior that everything before the first `extends` tag6 unmodified lines24 to false which it does per default if it's not defined. Additionally a very25 basic 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::27 28- {% 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 linesmodified:examples/basic/test.py+2 added-2 removed
3 unmodified lines4 env = 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 linesmodified:tests/test_ext.py+4 added-4 removed
16 unmodified lines17 _gettext_re = re.compile(r"_\((.*?)\)", re.DOTALL)18 19 20 i18n_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 line29 "stringformat.html": '{{ _("User: %(num)s")|format(num=user_count) }}',30 }31 32 newstyle_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 linesmodified:tests/test_inheritance.py+43 added-40 removed
147 unmodified lines148 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"161 162 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"180 181 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]"194 195 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 lines237 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 lines249 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 lines265 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 lines286 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 lines303 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")310 311 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 lines335 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)))353 354 355 class TestBugFix:356 def test_fixed_macro_scoping_bug(self, env):49 unmodified linesmodified:CONTRIBUTING.rst+2 added-2 removed
139 unmodified lines140 $ git fetch origin141 $ git checkout -b your-branch-name origin/1.1.x142 143 If you're submitting a feature addition or change, branch off of the144- "master" branch.144+ "main" branch.145 146 .. code-block:: text147 148 $ git fetch origin149- $ git checkout -b your-branch-name origin/master149+ $ git checkout -b your-branch-name origin/main150 151 - Using your favorite editor, make your changes,152 `committing as you go`_.153 - Include tests that cover any code changes you make. Make sure the63 unmodified lines