-
Notifications
You must be signed in to change notification settings - Fork 0
Email templating engine #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
stefanotroncaro
wants to merge
16
commits into
feat/email-service-async
Choose a base branch
from
feat/email-templates
base: feat/email-service-async
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
3f09790
build: bump python to 3.13.8
stefanotroncaro 0e309d5
build: bump dependencies
stefanotroncaro fc5371d
Merge pull request #31 from Light-it-labs/build/bump-python-to-3.13.8
DanTcheche 164fb22
Merge branch 'main' into feat/email-templates
stefanotroncaro abd2932
feat: email templates service
stefanotroncaro 677de7f
feat: refactor email service to use template service
stefanotroncaro 10b02ae
fix: test environment
stefanotroncaro 270315a
fix: wrong kwargs for other email
stefanotroncaro 4201a54
feat: component based template
stefanotroncaro dee7352
refactor: templates into a module
stefanotroncaro a4e7079
feat: mjml rendering
stefanotroncaro 1a8c486
refactor: templates out of emails/notifications module
stefanotroncaro 939e560
refactor: template path declaration
stefanotroncaro 49919f3
feat: extract template layout
stefanotroncaro 3502681
feat: component based template
stefanotroncaro 73c6c7f
refactor: remove comment
stefanotroncaro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 3.12.9 | ||
| 3.13.8 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from enum import Enum | ||
| from typing import Any, ClassVar, Literal, TypedDict, Unpack, overload | ||
|
|
||
| from jinja2 import Environment, FileSystemLoader | ||
|
|
||
|
|
||
| class EmailTemplate(Enum): | ||
| WELCOME = "welcome.j2" | ||
| OTHER = "_base.j2" | ||
|
|
||
|
|
||
| class _WelcomeKwargs(TypedDict): | ||
| name: str | ||
|
|
||
|
|
||
| class _OtherKwargs(TypedDict): | ||
| pass | ||
|
|
||
|
|
||
| class EmailTemplatesService: | ||
| _instance: ClassVar[EmailTemplatesService | None] = None | ||
| _environment: ClassVar[Environment] | ||
|
|
||
| def __new__(cls) -> EmailTemplatesService: | ||
| if cls._instance: | ||
| return cls._instance | ||
|
|
||
| cls._environment = Environment( | ||
| loader=FileSystemLoader("app/emails/templates"), | ||
| ) | ||
|
|
||
| cls._instance = super().__new__(cls) | ||
| return cls._instance | ||
|
|
||
| @overload | ||
| def render( | ||
| self, | ||
| template: Literal[EmailTemplate.WELCOME], | ||
| **kw: Unpack[_WelcomeKwargs], | ||
| ) -> str: ... | ||
| @overload | ||
| def render( | ||
| self, | ||
| template: Literal[EmailTemplate.OTHER], | ||
| **kw: Unpack[_OtherKwargs], | ||
| ) -> str: ... | ||
|
|
||
| def render(self, template: EmailTemplate, **kw: Any) -> str: | ||
| jinja_template = self._environment.get_template(template.value) | ||
| return jinja_template.render(**kw) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| {% extends "_base.j2" %} | ||
|
|
||
| {% block title %} | ||
| Welcome | ||
| {% endblock title %} | ||
|
|
||
| {% block body %} | ||
| <h1>Welcome {{ name }}</h1> | ||
| {% endblock body %} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.