@@ 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