def __init__(self, loadpaths=[]): """Create a new HDF dataset. The loadpaths parameter can be used to specify a sequence of paths under which ClearSilver will search for template files: >>> hdf = HDFWrapper(loadpaths=['/etc/templates', ... '/home/john/templates']) >>> print hdf hdf { loadpaths { 0 = /etc/templates 1 = /home/john/templates } } """ try: import neo_cgi # The following line is needed so that ClearSilver can be loaded when # we are being run in multiple interpreters under mod_python neo_cgi.update() import neo_util self.hdf = neo_util.HDF() self.has_clearsilver = True except ImportError, e: self.has_clearsilver = False
def __init__(self, loadpaths=[]): """Create a new HDF dataset. The loadpaths parameter can be used to specify a sequence of paths under which ClearSilver will search for template files: >>> hdf = HDFWrapper(loadpaths=['/etc/templates', ... '/home/john/templates']) >>> print hdf hdf { loadpaths { 0 = /etc/templates 1 = /home/john/templates } } """ try: import neo_cgi # The following line is needed so that ClearSilver can be loaded when # we are being run in multiple interpreters under mod_python neo_cgi.update() import neo_util self.hdf = neo_util.HDF() except ImportError, e: raise TracError, "ClearSilver not installed (%s)" % e
def init_request(self): import neo_cgi # The following line is needed so that ClearSilver can be loaded when # we are being run in multiple interpreters under mod_python neo_cgi.update() import neo_cs import neo_util import Cookie self.hdf = neo_util.HDF() self.incookie = Cookie.SimpleCookie() self.outcookie = Cookie.SimpleCookie()
def clearsilver(dirname, verbose=False): try: import neo_cgi except ImportError: return lambda: None neo_cgi.update() import neo_util import neo_cs def render(): hdf = neo_util.HDF() hdf.setValue('hdf.loadpaths.0', dirname) hdf.setValue('title', escape('Just a test')) hdf.setValue('user', escape('joe')) for num in range(1, 15): hdf.setValue('items.%d' % (num - 1), escape('Number %d' % num)) cs = neo_cs.CS(hdf) cs.parseFile('template.cs') return cs.render() if verbose: print render() return render
def display(self, cs, content_type='text/html', response=200): import neo_cgi # The following line is needed so that ClearSilver can be loaded when # we are being run in multiple interpreters under mod_python neo_cgi.update() import neo_cs import neo_util if type(cs) == type(''): filename = cs cs = neo_cs.CS(self.hdf) cs.parseFile(filename) data = cs.render() self.send_response(response) self.send_header('Cache-control', 'no-cache') self.send_header('Expires', 'Fri, 01 Jan 1999 00:00:00 GMT') self.send_header('Content-Type', content_type + ';charset=utf-8') self.send_header('Content-Length', len(data)) cookies = self.outcookie.output(header='') for cookie in cookies.splitlines(): self.send_header('Set-Cookie', cookie.strip()) self.end_headers() if self.command != 'HEAD': self.write(data)
def clearsilver(dirname, verbose=False): try: import neo_cgi except ImportError: print("ClearSilver not installed, skipping") return lambda: None neo_cgi.update() import neo_util import neo_cs def render(): hdf = neo_util.HDF() hdf.setValue("hdf.loadpaths.0", dirname) hdf.setValue("title", escape("Just a test")) hdf.setValue("user", escape("joe")) for num in range(1, 15): hdf.setValue("items.%d" % (num - 1), escape("Number %d" % num)) cs = neo_cs.CS(hdf) cs.parseFile("template.cs") return cs.render() if verbose: print(render()) return render
# this starts up the python enviroment # # The root dir should point to the top of the python tree import os, sys ROOT_DIR = "../../.." sys.path.insert(0, ROOT_DIR) sys.path.insert(0, "../..") from neo_paths import paths sys.path = paths(ROOT_DIR) + sys.path # don't put anything above this because the path isn't # extended yet... import neo_cgi try: # newer versions have an update function that will guaruntee that # neo_util and neo_cs are also loaded when used with non single interpreter # versions of PyApache neo_cgi.update() except: pass
# this starts up the T-environment... # # The root dir should point to the top of the python tree import sys ROOT_DIR = "./" sys.path.insert(0, ROOT_DIR) from tpaths import paths sys.path = paths(ROOT_DIR) + sys.path # don't put anything above this because the path isn't # extended yet... import neo_cgi try: # newer versions have an update function that will guaruntee that # neo_util and neo_cs are also loaded when used with non single interpreter # versions of PyApache neo_cgi.update() except: pass