1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from template import render


html_template = """
<html>
 <h1>Hello {{= username }}</h1><br/>
 {{ if session_id=="xyz": }}
 {{   # indentation doesn't matter.. }}
   this isn't printed unless if-statement matches
 {{ else: }}
   instead this would be shown
 {{ pass  # each if/for/while statements (stmts that "indent your code"), must end with pass }}
 {{ for e in elements: }}   - {{=e}}
 {{ pass }}

 {{ # demo of looping }}
 {{ if 1: }} 
   {{ for i in xrange(10): }}<br/>{{ pass }}
{{ pass }}

{{ # imported function }}
100 chars of google html get:
{{ =lam()[:100] }}

{{ # you can access the whole language with this }}
{{ =f()}}
"""


import urllib2

def f(): return "you can do whatever"

environment = dict(
    elements=[1, 2, 3],
    username="mortn",
    session_id="xyz",
    lam=lambda x=0: urllib2.urlopen("http://google.com").read(),
    f=f,
    )

#render(content=open("filename").read(), context=environment)
print render(content=html_template, context=environment)