Skip to content

Latest commit

 

History

History
56 lines (42 loc) · 826 Bytes

README.md

File metadata and controls

56 lines (42 loc) · 826 Bytes

minja

[ Work in progress ]

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!

    &lt;h1&gt;Sup? I&#39;m escaped&lt;/h1&gt;
    <b>bye</b>
    heya


    1


    
        1
    
        2
    
        3
    
        4