Commits

Ralph Bean committed 4694aac

Added support for chameleon.

Comments (0)

Files changed (3)

 _extra_mako = ["Mako >= 0.1.1"]
 _extra_jinja = ["jinja2"]
 _extra_kajiki = ["kajiki"]
+_extra_chameleon = ["chameleon"]
 
 setup(
     name='tw2.core',
         'FormEncode',
         'WebTest',
         'strainer',
-    ] +  _extra_genshi + _extra_mako + _extra_jinja + _extra_kajiki,
+    ] + \
+    _extra_genshi + \
+    _extra_mako + \
+    _extra_jinja + \
+    _extra_kajiki + \
+    _extra_chameleon,
+
     test_suite = 'nose.collector',
     extras_require = {
         'genshi': _extra_genshi,
         'mako': _extra_mako,
         'jinja': _extra_jinja,
         'kajiki': _extra_kajiki,
+        'chameleon': _extra_chameleon,
         },
     url = "http://toscawidgets.org/",
     download_url = "http://toscawidgets.org/download/",

tests/test_template.py

 from nose.tools import raises, eq_
 
 # TBD: only test engines that are installed
-engines = ['genshi', 'mako', 'jinja', 'kajiki']
+engines = ['genshi', 'mako', 'jinja', 'kajiki', 'chameleon']
 
 
 class TestWD(twc.Widget):

tw2/core/templating.py

     'genshi_abs': ['html'],  # just for backwards compatibility with tw2 2.0.0
     'jinja': ['jinja', 'html'],
     'kajiki': ['kajiki', 'html'],
+    'chameleon': ['pt'],
 }
 
 
             mw = rl['middleware']
         pref_rend_eng = mw.config.preferred_rendering_engines
     except (KeyError, AttributeError):
-        pref_rend_eng = ['mako', 'genshi', 'jinja', 'kajiki']
+        pref_rend_eng = ['mako', 'genshi', 'jinja', 'kajiki', 'chameleon']
 
     # find the first file in the preffered engines available for templating
     for engine_name in pref_rend_eng:
             pass
 
     if not mw.config.strict_engine_selection:
-        pref_rend_eng = ['mako', 'genshi', 'jinja', 'kajiki']
+        pref_rend_eng = ['mako', 'genshi', 'jinja', 'kajiki', 'chameleon']
         for engine_name in pref_rend_eng:
             try:
                 get_source(engine_name, template_name)
         import kajiki
         tmpl = kajiki.XMLTemplate(src)
         return lambda kwargs: literal(tmpl(kwargs).render())
+    elif engine_name == 'chameleon':
+        import chameleon
+        tmpl = chameleon.PageTemplate(src, filename=filename)
+        return lambda kwargs: literal(tmpl.render(**kwargs).strip())
 
     raise NotImplementedError("Unhandled engine")
 
 
     # Load the template source
     source = get_source(engine_name, template_name, inline)
+
     # Establish the render function
     callback = get_render_callable(
         engine_name, displays_on, source, template_name)
+
     # Do it
     return callback(kwargs)