File: bottleTemplate.py

package info (click to toggle)
okasha 0.2.4-4
  • links: PTS, VCS
  • area: non-free
  • in suites: bullseye, sid
  • size: 856 kB
  • sloc: python: 1,092; sh: 29; makefile: 7
file content (47 lines) | stat: -rw-r--r-- 1,517 bytes parent folder | download
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
45
46
47
# -*- coding: UTF-8 -*-
"""
Okasha - a very simple WSGI webframe work
Copyright © 2009, Muayyad Alsadi <alsadi@ojuba.org>

    Released under terms of Waqf Public License.
    This program is free software; you can redistribute it and/or modify
    it under the terms of the latest version Waqf Public License as
    published by Ojuba.org.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

    The Latest version of the license can be found on
    "http://waqf.ojuba.org/license"

this is integrates bottle's SimpleTemplate into okasha
for details and sytax visit http://bottle.paws.de/docs/dev/stpl.html
"""

import sys, os, os.path
from .baseWebApp import fileNotFoundException
from .bottleTemplateSegment import SimpleTemplate, TemplateError

class bottleTemplate(object):
  def __init__(self, *a, **kw):
    self._tmp=None

  def _load(self, rq, bfn=None, **kw):
    if hasattr(rq.webapp._templatesDir, '__iter__'): d=rq.webapp._templatesDir
    else: d=[rq.webapp._templatesDir]
    if not bfn: bfn='root.tpl'
    try: self._tmp=SimpleTemplate(name=bfn, lookup=d)
    except:
      rq.webapp._logger.debug('template error fn=[%s]' % bfn)
      raise
    # FIXME: check for valid template

  def __call__(self, rq, o, *a, **kw):
    if not self._tmp: self._load(rq, *a, **kw)
    d=kw.copy()
    d.update(o)
    d['_r']=rq.response
    return self._tmp.render(**d)