Skip to content

Commit

Permalink
Make .jinja the default extension for Jinja templates
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertoPrevato authored Aug 21, 2023
1 parent 9cf0116 commit bed3a99
Show file tree
Hide file tree
Showing 12 changed files with 14 additions and 9 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion blacksheep/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
used types to reduce the verbosity of the imports statements.
"""
__author__ = "Roberto Prevato <[email protected]>"
__version__ = "2.0a9"
__version__ = "2.0a10"

from .contents import Content as Content
from .contents import FormContent as FormContent
Expand Down
6 changes: 4 additions & 2 deletions blacksheep/server/rendering/jinja2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
6 changes: 2 additions & 4 deletions tests/test_templating.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit bed3a99

Please sign in to comment.