There are two decorators for using kid from within Colubrid: a cached and an uncached version.
import os
from colubrid import HttpResponse
from kid import load_template
searchpath = 'templates'
def render(name):
path = os.path.join(searchpath, '%s.kid' % name)
def proxy(f):
def on_call(*args, **kwargs):
c = f(*args, **kwargs) or {}
t = Template(path, '', False)
for key, value in c.iteritems():
setattr(t, key, value)
return HttpResponse(t.serialize())
return on_call
return proxy
import os
from colubrid import HttpResponse
from kid import Template
searchpath = 'templates'
def render(name):
path = os.path.join(searchpath, '%s.kid' % name)
def proxy(f):
def on_call(*args, **kwargs):
c = f(*args, **kwargs) or {}
t = Template(file=path, **c)
return HttpResponse(t.serialize())
return on_call
return proxy
You can use it from any Colubrid application type:
from colubrid import RegexApplication, execute
import time
class MyApplication(RegexApplication):
urls = [
(r'^index$', 'index')
]
@render('index')
def index(self):
return {
'now': time.time()
}
app = MyApplication
if __name__ == '__main__':
execute()
Here the index.kid template from the example above:
<?xml version="1.0" encoding="utf-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:py="http://purl.org/kid/ns#">
<body>
<h1>Welcome from the Index</h1>
The current Unix Timestamp is <span py:replace="now">timestamp here</span>
</body>
</html>