Skip to content
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

feat(template): add template_str for rendering from strings #2689

Merged
merged 29 commits into from
Nov 17, 2023

Conversation

JacobCoffee
Copy link
Member

@JacobCoffee JacobCoffee commented Nov 17, 2023

Pull Request Checklist

  • New code has 100% test coverage
  • (If applicable) The prose documentation has been updated to reflect the changes introduced by this PR
  • (If applicable) The reference documentation has been updated to reflect the changes introduced by this PR
  • Pre-Commit Checks were ran and passed
  • Tests were ran and passed

Description

  • Adds a method to render HTML templates from strings

Close Issue(s)

@JacobCoffee JacobCoffee requested review from a team as code owners November 17, 2023 01:29
@JacobCoffee
Copy link
Member Author

JacobCoffee commented Nov 17, 2023

Tested so far using this MCVE:
https://paste.pythondiscord.com/QHAQ

Jinja
image
Mako
image
MiniJinja
image

@JacobCoffee
Copy link
Member Author

Can do the tests and docs if it works out

@JacobCoffee
Copy link
Member Author

Note to add @Alc-Alc as co-contributor for his suggestion on #681e87d

Copy link
Contributor

@peterschutt peterschutt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, cheers!

litestar/contrib/mako.py Show resolved Hide resolved
litestar/response/template.py Show resolved Hide resolved
litestar/response/template.py Outdated Show resolved Hide resolved
litestar/response/template.py Outdated Show resolved Hide resolved
litestar/contrib/minijinja.py Outdated Show resolved Hide resolved
litestar/response/template.py Outdated Show resolved Hide resolved
docs/examples/templating/returning_templates_jinja.py Outdated Show resolved Hide resolved
litestar/response/template.py Outdated Show resolved Hide resolved
@guacs
Copy link
Member

guacs commented Nov 17, 2023

This is a really nice feature to add!

JacobCoffee and others added 3 commits November 16, 2023 22:57
converge boilerplate 3x into 1x
Co-authored-by: guacs <126393040+guacs@users.noreply.github.com>
Copy link
Member

@guacs guacs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@JacobCoffee JacobCoffee enabled auto-merge (squash) November 17, 2023 14:43
@JacobCoffee
Copy link
Member Author

JacobCoffee commented Nov 17, 2023

@peterschutt / @guacs can you check the latest here: e653101?

I am only running into litestar/response/template.py:163: error: Item "None" of "Optional[TemplateEngineProtocol[Any, Any]]" has no attribute "render_string" [union-attr] but i cant fight it any longer :\

litestar/response/template.py Outdated Show resolved Hide resolved
litestar/response/template.py Outdated Show resolved Hide resolved
litestar/response/template.py Show resolved Hide resolved
@JacobCoffee JacobCoffee enabled auto-merge (squash) November 17, 2023 23:31
@JacobCoffee JacobCoffee merged commit d536235 into main Nov 17, 2023
14 checks passed
@JacobCoffee JacobCoffee deleted the 2687-template-str branch November 17, 2023 23:32
Copy link

sonarcloud bot commented Nov 17, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

97.4% 97.4% Coverage
0.0% 0.0% Duplication

Copy link

Documentation preview will be available shortly at https://litestar-org.github.io/litestar-docs-preview/2689

@guacs
Copy link
Member

guacs commented Nov 18, 2023

@peterschutt / @guacs can you check the latest here: e653101?

I am only running into litestar/response/template.py:163: error: Item "None" of "Optional[TemplateEngineProtocol[Any, Any]]" has no attribute "render_string" [union-attr] but i cant fight it any longer :\

@JacobCoffee, sorry, I just saw this now :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhancement: Allow creating templates from strings
3 participants