Repository: Neoteroi/BlackSheep
Pull request #406 (2023-08-06 21:51:24)

add: support for jinja ext
Many editors and tools look for the `.html.jinja` extension in order to provide formatting, color highlighting, styling, intellisense, etc. To support those use cases, don't try to append the `.html` extension to templates that already specify the `.jinja` extension, and also do autoescaping for `.jinja` files.

I'm also open to making it ignore only `.html.jinja` instead of just `.jinja`, but that would force folks into using `.jinja.html` instead, which feels like an incorrect ext.

codecov-commenter: ## [Codecov](https://app.codecov.io/gh/Neoteroi/BlackSheep/pull/406?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Neoteroi) Report
Patch coverage: **`100.00%`** and project coverage change: **`-0.04%`** :warning:
> Comparison is base [(`011d1ac`)](https://app.codecov.io/gh/Neoteroi/BlackSheep/commit/011d1ac693f5ac62a5ea38aa5200da4d7fbbb4f4?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Neoteroi) 97.57% compared to head [(`0f4e301`)](https://app.codecov.io/gh/Neoteroi/BlackSheep/pull/406?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Neoteroi) 97.53%.

:exclamation: Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please [install the Github App Integration](https://github.com/apps/codecov) for your organization. [Read more](https://about.codecov.io/blog/codecov-is-updating-its-github-integration/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Neoteroi).

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##             main     #406      +/-   ##
==========================================
- Coverage   97.57%   97.53%   -0.04%     
==========================================
  Files          66       66              
  Lines        6256     6256              
==========================================
- Hits         6104     6102       -2     
- Misses        152      154       +2     
```


| [Files Changed](https://app.codecov.io/gh/Neoteroi/BlackSheep/pull/406?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Neoteroi) | Coverage Δ | |
|---|---|---|
| [blacksheep/server/rendering/jinja2.py](https://app.codecov.io/gh/Neoteroi/BlackSheep/pull/406?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Neoteroi#diff-YmxhY2tzaGVlcC9zZXJ2ZXIvcmVuZGVyaW5nL2ppbmphMi5weQ==) | `98.57% <100.00%> (ø)` | |

... and [2 files with indirect coverage changes](https://app.codecov.io/gh/Neoteroi/BlackSheep/pull/406/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Neoteroi)


</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/Neoteroi/BlackSheep/pull/406?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Neoteroi).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Neoteroi).


Patch:
diff --git a/blacksheep/server/rendering/jinja2.py b/blacksheep/server/rendering/jinja2.py
index 91069e1..e93084b 100644
--- a/blacksheep/server/rendering/jinja2.py
+++ b/blacksheep/server/rendering/jinja2.py
@@ -14,7 +14,7 @@ from .abc import Renderer
 
 @lru_cache(1200)
 def get_template_name(name: str) -> str:
-    if not name.endswith(".html"):
+    if not name.endswith(".html") and not name.endswith(".jinja"):
         return name + ".html"
     return name
 
@@ -93,7 +93,7 @@ class JinjaRenderer(Renderer):
                 os.environ.get("APP_JINJA_PACKAGE_NAME", "app"),
                 os.environ.get("APP_JINJA_PACKAGE_PATH", "views"),
             ),
-            autoescape=select_autoescape(["html", "xml"]),
+            autoescape=select_autoescape(["html", "xml", "jinja"]),
             auto_reload=bool(os.environ.get("APP_JINJA_DEBUG", "")) or debug,
             enable_async=bool(os.environ.get("APP_JINJA_ENABLE_ASYNC", ""))
             or enable_async,


Test patch:
diff --git a/tests/test_templating.py b/tests/test_templating.py
index ca3b882..7fc3d31 100644
--- a/tests/test_templating.py
+++ b/tests/test_templating.py
@@ -324,6 +324,8 @@ async def test_controller_conventional_view_name_extraneous_function(home_model)
     [
         ("index", "index.html"),
         ("index.html", "index.html"),
+        ("index.html.jinja", "index.html.jinja"),
+        ("index.jinja", "index.jinja"),
         ("default", "default.html"),
     ],
 )