A basic (and heavily jinja inspired) python template engine intended to teach myself basic compiler design.
from minja import Template
template = '''{{hello}}
{% if 1 < 2 %}
<b>{{hello2}}</b>
{{func('bye')}}
heya
{% endif %}
{% with x, y = (1, 'test') %}
{{x}}
{% endwith %}
{% block test %}
{% for i in get_list() %}
{{i}}
{% endfor %}
{% endblock %}
'''
def f():
return [1,2,3,4]
t = Template(template, autoescape=True)
print(
t.render(
hello="Hey there!",
hello2="<h1>Sup? I'm escaped</h1>",
get_list=f,
func=lambda x: x))
Output:
Hey there!
<h1>Sup? I'm escaped</h1>
<b>bye</b>
heya
1
1
2
3
4