~tieong/notjinja2

17d547b497acf63e574fa3468bf23593e23049aa — Thomas Ieong 1 year, 5 months ago 09de7a9
Added meaningful errors
1 files changed, 8 insertions(+), 3 deletions(-)

M notjinja2.py
M notjinja2.py => notjinja2.py +8 -3
@@ 38,12 38,14 @@ class Template:
                elif is_loop:
                    self.parse_loop(split_token)
                else:
                    raise ValueError("Unknown control structure!")
                    raise ValueError("Unknown control structure!", " ", token)
                if self.buffer and (is_conditional or is_loop):
                    self.add_line(" ".join(self.buffer) + ":")
                    self.indent()
                    self.buffer.clear()
            elif token.startswith("{{"):
                if len(split_token) <= 1:
                    raise ValueError("Can't parse this token", " ", token)
                item = str(self.do_dots(str(split_token[1]).replace("\n", "")))
                self.add_line("output += {}".format(item))
            elif token.startswith("{#"):


@@ 55,7 57,10 @@ class Template:
        self.dedent()

        assert not self.buffer
        assert self.INDENT == 0
        if self.INDENT != 0:
            raise ValueError(
                "Control structures not balanced! Check the endif,endfor tags!"
            )

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


@@ 82,7 87,6 @@ class Template:
                    )
                else:
                    data = "data['{func}']({d})".format(func=function, d=data)
            data = "str({})".format(data)
        elif "." in token:
            split_token = token.split(".")
            if split_token[0] in self.globs:


@@ 94,6 98,7 @@ class Template:
                data = "data['{}']".format(token)
            else:
                data = token
                data = "str({})".format(data)
        else:
            data = token