| 19 | |
| 20 | @classmethod |
| 21 | def compile(cls, template): |
| 22 | tokens = [] |
| 23 | for i, part in enumerate(cls.delimiter.split(template)): |
| 24 | if i % 2 == 0: |
| 25 | if part: |
| 26 | tokens.append((False, part.replace("$\\{", "${"))) |
| 27 | else: |
| 28 | if not part.strip(): |
| 29 | continue |
| 30 | lines = part.replace("}\\$", "}$").splitlines() |
| 31 | margin = min(len(l) - len(l.lstrip()) for l in lines if l.strip()) |
| 32 | realigned = "\n".join(l[margin:] for l in lines) |
| 33 | code = compile(realigned, "<templite %r>" % (realigned[:20],), "exec") |
| 34 | tokens.append((True, code)) |
| 35 | return tokens |
| 36 | |
| 37 | def render(__self, __namespace = None, **kw): |
| 38 | """ |