~tieong/notjinja2

e16b013eb4e6694645e21f0808cb6568269dd8a5 — Thomas Ieong 1 year, 7 months ago a531d7b
Added type hints
1 files changed, 8 insertions(+), 7 deletions(-)

M notjinja2.py
M notjinja2.py => notjinja2.py +8 -7
@@ 7,6 7,7 @@ Simple template engine with a jinja syntax.
"""

import re
from typing import List
from keyword import iskeyword

TOKENS = re.compile(r"(?s)({%.*?%}|{#.*?#}|{{.*?}})")


@@ 56,7 57,7 @@ class Template:
        assert not self.buffer
        assert self.INDENT == 0

    def do_dots(self, token):
    def do_dots(self, token: str) -> str:
        data = ""

        if "|" in token:


@@ 85,7 86,7 @@ class Template:

        return data

    def parse_loop(self, tokens):
    def parse_loop(self, tokens: List[str]) -> None:
        for token in tokens:
            if token in ("{%", "%}"):
                pass


@@ 98,7 99,7 @@ class Template:
            else:
                self.buffer.append(token)

    def parse_conditionals(self, tokens):
    def parse_conditionals(self, tokens: List[str]) -> None:
        for token in tokens:
            if token in ("{%", "%}"):
                pass


@@ 112,16 113,16 @@ class Template:
            else:
                self.buffer.append(self.do_dots(token))

    def add_line(self, line):
    def add_line(self, line) -> None:
        self.code += " " * self.INDENT + line + "\n"

    def indent(self):
    def indent(self) -> None:
        self.INDENT += 4

    def dedent(self):
    def dedent(self) -> None:
        self.INDENT -= 4

    def render(self):
    def render(self) -> str:
        exec(self.code)
        return eval("template_render")(self.globs)