A Python template engine inspired by EJS for dynamic HTML rendering.
Project description
PyEJS
A Python template engine inspired by EJS
Render dynamic HTML using <%= variable %> for data and <% code %> for logic like loops and conditionals.
✨ Features
- Variable interpolation:
<%= variable %> - Code blocks:
<% code %>(loops, conditionals, etc.) - Render templates from strings or files
- Simple and lightweight
- Custom error handling for missing variables or syntax errors
⚙️ Installation
git clone https://github.com/your-username/pyejs.git
cd pyejs
🚀 Usage
🔹 Render from string
from pyejs import Template
template = """
<h1>Hello, <%= user %>!</h1>
<ul>
<%
for item in items:
output.append(f" <li>{item}</li>\\n")
%>
</ul>
"""
context = {
"user": "Alice",
"items": ["Apple", "Banana", "Cherry"]
}
t = Template(template)
html = t.render(context)
print(html)
🔹 Render from file
from pyejs import Template
html = Template.render_file("templates/my_template.html", context)
print(html)
⚠️ Error Handling
TemplateVariableError → Raised if a variable is missing in context
TemplateSyntaxError → Raised for invalid code blocks
🛠️ Roadmap
✅ Variable interpolation <%= %>
✅ Code blocks <% %>
⚡ Support if-else and nested loops
⚡ Template includes <% include %>
⚡ CLI tool for rendering templates from terminal
🤝 Contributing
Contributions are welcome!
Feel free to submit issues, feature requests, or pull requests
# Optional: install in your environment
pip install .
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pyejs-0.1.0.tar.gz
(4.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
pyejs-0.1.0-py3-none-any.whl
(5.0 kB
view details)
File details
Details for the file pyejs-0.1.0.tar.gz.
File metadata
- Download URL: pyejs-0.1.0.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d2dee8ceb10451e326b59d1e3e654fc2295f3f801c781dedc06cdb4e3048aabd
|
|
| MD5 |
4170203c155a319ceb65ba1c253e728b
|
|
| BLAKE2b-256 |
f47a6d613bc980f694534f1d9150bb340c74d1c182aefaa98034773b488d140b
|
File details
Details for the file pyejs-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pyejs-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c67fe403e3d2a03c97e168d932a5c304fa2d1a3c3f86e61efab51fb49f409f8a
|
|
| MD5 |
e058c544fc774dadf1cc5796d2188f7d
|
|
| BLAKE2b-256 |
395228fc556c9a365a052f1526411845457867d3f14bca7647e2f82ff439a3e7
|