Skip to content

Commit

Permalink
rename default branch in files
Browse files Browse the repository at this point in the history
  • Loading branch information
davidism committed May 11, 2021
1 parent e7dce0b commit 9b86bbc
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 56 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ name: Tests
on:
push:
branches:
- master
- main
- '*.x'
paths-ignore:
- 'docs/**'
- '*.md'
- '*.rst'
pull_request:
branches:
- master
- main
- '*.x'
paths-ignore:
- 'docs/**'
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ Start coding
$ git checkout -b your-branch-name origin/1.1.x
If you're submitting a feature addition or change, branch off of the
"master" branch.
"main" branch.

.. code-block:: text
$ git fetch origin
$ git checkout -b your-branch-name origin/master
$ git checkout -b your-branch-name origin/main
- Using your favorite editor, make your changes,
`committing as you go`_.
Expand Down
4 changes: 2 additions & 2 deletions docs/templates.rst
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ this template "extends" another template. When the template system evaluates
this template, it first locates the parent. The extends tag should be the
first tag in the template. Everything before it is printed out normally and
may cause confusion. For details about this behavior and how to take
advantage of it, see :ref:`null-master-fallback`. Also a block will always be
advantage of it, see :ref:`null-default-fallback`. Also a block will always be
filled in regardless of whether the surrounding condition is evaluated to be true
or false.

Expand Down Expand Up @@ -1430,7 +1430,7 @@ It is also possible to use inline `if` expressions. These are useful in some
situations. For example, you can use this to extend from one template if a
variable is defined, otherwise from the default layout template::

{% extends layout_template if layout_template is defined else 'master.html' %}
{% extends layout_template if layout_template is defined else 'default.html' %}

The general syntax is ``<do something> if <something is true> else <do
something else>``.
Expand Down
8 changes: 4 additions & 4 deletions docs/tricks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ This part of the documentation shows some tips and tricks for Jinja
templates.


.. _null-master-fallback:
.. _null-default-fallback:

Null-Master Fallback
--------------------
Null-Default Fallback
---------------------

Jinja supports dynamic inheritance and does not distinguish between parent
and child template as long as no `extends` tag is visited. While this leads
Expand All @@ -25,7 +25,7 @@ to false which it does per default if it's not defined. Additionally a very
basic skeleton is added to the file so that if it's indeed rendered with
`standalone` set to `True` a very basic HTML skeleton is added::

{% if not standalone %}{% extends 'master.html' %}{% endif -%}
{% if not standalone %}{% extends 'default.html' %}{% endif -%}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<title>{% block title %}The Page Title{% endblock %}</title>
<link rel="stylesheet" href="style.css" type="text/css">
Expand Down
4 changes: 2 additions & 2 deletions examples/basic/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
loader=DictLoader(
{
"child.html": """\
{% extends master_layout or 'master.html' %}
{% extends default_layout or 'default.html' %}
{% include helpers = 'helpers.html' %}
{% macro get_the_answer() %}42{% endmacro %}
{% title = 'Hello World' %}
Expand All @@ -14,7 +14,7 @@
{{ helpers.conspirate() }}
{% endblock %}
""",
"master.html": """\
"default.html": """\
<!doctype html>
<title>{{ title }}</title>
{% block body %}{% endblock %}
Expand Down
8 changes: 4 additions & 4 deletions tests/test_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@


i18n_templates = {
"master.html": '<title>{{ page_title|default(_("missing")) }}</title>'
"default.html": '<title>{{ page_title|default(_("missing")) }}</title>'
"{% block body %}{% endblock %}",
"child.html": '{% extends "master.html" %}{% block body %}'
"child.html": '{% extends "default.html" %}{% block body %}'
"{% trans %}watch out{% endtrans %}{% endblock %}",
"plural.html": "{% trans user_count %}One user online{% pluralize %}"
"{{ user_count }} users online{% endtrans %}",
Expand All @@ -30,9 +30,9 @@
}

newstyle_i18n_templates = {
"master.html": '<title>{{ page_title|default(_("missing")) }}</title>'
"default.html": '<title>{{ page_title|default(_("missing")) }}</title>'
"{% block body %}{% endblock %}",
"child.html": '{% extends "master.html" %}{% block body %}'
"child.html": '{% extends "default.html" %}{% block body %}'
"{% trans %}watch out{% endtrans %}{% endblock %}",
"plural.html": "{% trans user_count %}One user online{% pluralize %}"
"{{ user_count }} users online{% endtrans %}",
Expand Down
83 changes: 43 additions & 40 deletions tests/test_inheritance.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,57 +149,60 @@ def test_dynamic_inheritance(self, env):
env = Environment(
loader=DictLoader(
{
"master1": "MASTER1{% block x %}{% endblock %}",
"master2": "MASTER2{% block x %}{% endblock %}",
"child": "{% extends master %}{% block x %}CHILD{% endblock %}",
"default1": "DEFAULT1{% block x %}{% endblock %}",
"default2": "DEFAULT2{% block x %}{% endblock %}",
"child": "{% extends default %}{% block x %}CHILD{% endblock %}",
}
)
)
tmpl = env.get_template("child")
for m in range(1, 3):
assert tmpl.render(master=f"master{m}") == f"MASTER{m}CHILD"
assert tmpl.render(default=f"default{m}") == f"DEFAULT{m}CHILD"

def test_multi_inheritance(self, env):
env = Environment(
loader=DictLoader(
{
"master1": "MASTER1{% block x %}{% endblock %}",
"master2": "MASTER2{% block x %}{% endblock %}",
"child": """{% if master %}{% extends master %}{% else %}{% extends
'master1' %}{% endif %}{% block x %}CHILD{% endblock %}""",
"default1": "DEFAULT1{% block x %}{% endblock %}",
"default2": "DEFAULT2{% block x %}{% endblock %}",
"child": (
"{% if default %}{% extends default %}{% else %}"
"{% extends 'default1' %}{% endif %}"
"{% block x %}CHILD{% endblock %}"
),
}
)
)
tmpl = env.get_template("child")
assert tmpl.render(master="master2") == "MASTER2CHILD"
assert tmpl.render(master="master1") == "MASTER1CHILD"
assert tmpl.render() == "MASTER1CHILD"
assert tmpl.render(default="default2") == "DEFAULT2CHILD"
assert tmpl.render(default="default1") == "DEFAULT1CHILD"
assert tmpl.render() == "DEFAULT1CHILD"

def test_scoped_block(self, env):
env = Environment(
loader=DictLoader(
{
"master.html": "{% for item in seq %}[{% block item scoped %}"
"default.html": "{% for item in seq %}[{% block item scoped %}"
"{% endblock %}]{% endfor %}"
}
)
)
t = env.from_string(
"{% extends 'master.html' %}{% block item %}{{ item }}{% endblock %}"
"{% extends 'default.html' %}{% block item %}{{ item }}{% endblock %}"
)
assert t.render(seq=list(range(5))) == "[0][1][2][3][4]"

def test_super_in_scoped_block(self, env):
env = Environment(
loader=DictLoader(
{
"master.html": "{% for item in seq %}[{% block item scoped %}"
"default.html": "{% for item in seq %}[{% block item scoped %}"
"{{ item }}{% endblock %}]{% endfor %}"
}
)
)
t = env.from_string(
'{% extends "master.html" %}{% block item %}'
'{% extends "default.html" %}{% block item %}'
"{{ super() }}|{{ item * 2 }}{% endblock %}"
)
assert t.render(seq=list(range(5))) == "[0|0][1|2][2|4][3|6][4|8]"
Expand Down Expand Up @@ -235,8 +238,8 @@ def test_level1_required(self, env):
env = Environment(
loader=DictLoader(
{
"master": "{% block x required %}{# comment #}\n {% endblock %}",
"level1": "{% extends 'master' %}{% block x %}[1]{% endblock %}",
"default": "{% block x required %}{# comment #}\n {% endblock %}",
"level1": "{% extends 'default' %}{% block x %}[1]{% endblock %}",
}
)
)
Expand All @@ -247,9 +250,9 @@ def test_level2_required(self, env):
env = Environment(
loader=DictLoader(
{
"master": "{% block x required %}{% endblock %}",
"level1": "{% extends 'master' %}{% block x %}[1]{% endblock %}",
"level2": "{% extends 'master' %}{% block x %}[2]{% endblock %}",
"default": "{% block x required %}{% endblock %}",
"level1": "{% extends 'default' %}{% block x %}[1]{% endblock %}",
"level2": "{% extends 'default' %}{% block x %}[2]{% endblock %}",
}
)
)
Expand All @@ -263,8 +266,8 @@ def test_level3_required(self, env):
env = Environment(
loader=DictLoader(
{
"master": "{% block x required %}{% endblock %}",
"level1": "{% extends 'master' %}",
"default": "{% block x required %}{% endblock %}",
"level1": "{% extends 'default' %}",
"level2": "{% extends 'level1' %}{% block x %}[2]{% endblock %}",
"level3": "{% extends 'level2' %}",
}
Expand All @@ -284,13 +287,13 @@ def test_invalid_required(self, env):
env = Environment(
loader=DictLoader(
{
"master": "{% block x required %}data {# #}{% endblock %}",
"master1": "{% block x required %}{% block y %}"
"default": "{% block x required %}data {# #}{% endblock %}",
"default1": "{% block x required %}{% block y %}"
"{% endblock %} {% endblock %}",
"master2": "{% block x required %}{% if true %}"
"default2": "{% block x required %}{% if true %}"
"{% endif %} {% endblock %}",
"level1": "{% if master %}{% extends master %}"
"{% else %}{% extends 'master' %}{% endif %}"
"level1": "{% if default %}{% extends default %}"
"{% else %}{% extends 'default' %}{% endif %}"
"{%- block x %}CHILD{% endblock %}",
}
)
Expand All @@ -301,21 +304,21 @@ def test_invalid_required(self, env):
TemplateSyntaxError,
match="Required blocks can only contain comments or whitespace",
):
assert t.render(master="master")
assert t.render(master="master2")
assert t.render(master="master3")
assert t.render(default="default")
assert t.render(default="default2")
assert t.render(default="default3")

def test_required_with_scope(self, env):
env = Environment(
loader=DictLoader(
{
"master1": "{% for item in seq %}[{% block item scoped required %}"
"default1": "{% for item in seq %}[{% block item scoped required %}"
"{% endblock %}]{% endfor %}",
"child1": "{% extends 'master1' %}{% block item %}"
"child1": "{% extends 'default1' %}{% block item %}"
"{{ item }}{% endblock %}",
"master2": "{% for item in seq %}[{% block item required scoped %}"
"default2": "{% for item in seq %}[{% block item required scoped %}"
"{% endblock %}]{% endfor %}",
"child2": "{% extends 'master2' %}{% block item %}"
"child2": "{% extends 'default2' %}{% block item %}"
"{{ item }}{% endblock %}",
}
)
Expand All @@ -333,20 +336,20 @@ def test_duplicate_required_or_scoped(self, env):
env = Environment(
loader=DictLoader(
{
"master1": "{% for item in seq %}[{% block item "
"default1": "{% for item in seq %}[{% block item "
"scoped scoped %}}{{% endblock %}}]{{% endfor %}}",
"master2": "{% for item in seq %}[{% block item "
"default2": "{% for item in seq %}[{% block item "
"required required %}}{{% endblock %}}]{{% endfor %}}",
"child": "{% if master %}{% extends master %}{% else %}"
"{% extends 'master1' %}{% endif %}{%- block x %}"
"child": "{% if default %}{% extends default %}{% else %}"
"{% extends 'default1' %}{% endif %}{%- block x %}"
"CHILD{% endblock %}",
}
)
)
tmpl = env.get_template("child")
with pytest.raises(TemplateSyntaxError):
tmpl.render(master="master1", seq=list(range(3)))
tmpl.render(master="master2", seq=list(range(3)))
tmpl.render(default="default1", seq=list(range(3)))
tmpl.render(default="default2", seq=list(range(3)))


class TestBugFix:
Expand Down

0 comments on commit 9b86bbc

Please sign in to comment.