diff --git a/CHANGELOG.md b/CHANGELOG.md index 2af0e1f6..e57c9567 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,10 +5,15 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.0a10] - 2023-08-21 :broccoli: + +- Add support for `.jinja` extension by @thearchitector. +- Makes the `.jinja` extension default for Jinja templates. + ## [2.0a9] - 2023-07-14 -- Fixes bug #394, causing the `Content` max body size to be 2147483647 - (C int max value). Reported and fixed by @thomafred +- Fixes bug #394, causing the `Content` max body size to be 2147483647. + (C int max value). Reported and fixed by @thomafred. ## [2.0a8] - 2023-07-02 diff --git a/blacksheep/__init__.py b/blacksheep/__init__.py index 2242c0c3..58b61208 100644 --- a/blacksheep/__init__.py +++ b/blacksheep/__init__.py @@ -3,7 +3,7 @@ used types to reduce the verbosity of the imports statements. """ __author__ = "Roberto Prevato " -__version__ = "2.0a9" +__version__ = "2.0a10" from .contents import Content as Content from .contents import FormContent as FormContent diff --git a/blacksheep/server/rendering/jinja2.py b/blacksheep/server/rendering/jinja2.py index e93084bd..5e6851e7 100644 --- a/blacksheep/server/rendering/jinja2.py +++ b/blacksheep/server/rendering/jinja2.py @@ -11,11 +11,13 @@ from .abc import Renderer +_DEFAULT_TEMPLATES_EXTENSION = os.environ.get("APP_JINJA_EXTENSION", ".jinja") + @lru_cache(1200) def get_template_name(name: str) -> str: - if not name.endswith(".html") and not name.endswith(".jinja"): - return name + ".html" + if not name.endswith(_DEFAULT_TEMPLATES_EXTENSION): + return name + _DEFAULT_TEMPLATES_EXTENSION return name diff --git a/tests/test_templating.py b/tests/test_templating.py index 7fc3d312..4426df2b 100644 --- a/tests/test_templating.py +++ b/tests/test_templating.py @@ -322,11 +322,9 @@ def index(self): @pytest.mark.parametrize( "value,expected_name", [ - ("index", "index.html"), - ("index.html", "index.html"), - ("index.html.jinja", "index.html.jinja"), + ("index", "index.jinja"), ("index.jinja", "index.jinja"), - ("default", "default.html"), + ("default", "default.jinja"), ], ) def test_template_name(value, expected_name): diff --git a/tests/testapp/templates/form_1.html b/tests/testapp/templates/form_1.jinja similarity index 100% rename from tests/testapp/templates/form_1.html rename to tests/testapp/templates/form_1.jinja diff --git a/tests/testapp/templates/form_2.html b/tests/testapp/templates/form_2.jinja similarity index 100% rename from tests/testapp/templates/form_2.html rename to tests/testapp/templates/form_2.jinja diff --git a/tests/testapp/templates/home.html b/tests/testapp/templates/home.jinja similarity index 100% rename from tests/testapp/templates/home.html rename to tests/testapp/templates/home.jinja diff --git a/tests/testapp/templates/lorem/form_1.html b/tests/testapp/templates/lorem/form_1.jinja similarity index 100% rename from tests/testapp/templates/lorem/form_1.html rename to tests/testapp/templates/lorem/form_1.jinja diff --git a/tests/testapp/templates/lorem/hello.html b/tests/testapp/templates/lorem/hello.jinja similarity index 100% rename from tests/testapp/templates/lorem/hello.html rename to tests/testapp/templates/lorem/hello.jinja diff --git a/tests/testapp/templates/lorem/index.html b/tests/testapp/templates/lorem/index.jinja similarity index 100% rename from tests/testapp/templates/lorem/index.html rename to tests/testapp/templates/lorem/index.jinja diff --git a/tests/testapp/templates/lorem/nomodel.html b/tests/testapp/templates/lorem/nomodel.jinja similarity index 100% rename from tests/testapp/templates/lorem/nomodel.html rename to tests/testapp/templates/lorem/nomodel.jinja diff --git a/tests/testapp/templates/lorem/specific.html b/tests/testapp/templates/lorem/specific.jinja similarity index 100% rename from tests/testapp/templates/lorem/specific.html rename to tests/testapp/templates/lorem/specific.jinja