Permalink
Browse files

[svn] * Updated template options config to take template options for …

…multiple

  engines for less binding to Myghty.

--HG--
branch : trunk
  • Loading branch information...
1 parent 1bb889e commit 6bd88a112936cc4aa6e117b69476c638b20ac3fc bbangert committed Dec 31, 2006
View
@@ -2,6 +2,8 @@ Pylons Changelog
=================
0.9.5 (**svn**)
+* Updated template options config to take template options for multiple
+ engines for less binding to Myghty.
* Fixed paster shell incorrectly importing the the tuple (model,) as the
model object.
View
@@ -4,6 +4,7 @@
for Myghty, Paste errorware, and prefixing Routes if necessary.
"""
import os
+import re
from paste.deploy.converters import asbool
import pylons.templating
@@ -54,22 +55,38 @@ class Config(object):
Whether or not the ``c`` object should throw an attribute error when
access is attempted to an attribute that doesn't exist.
"""
- def __init__(self, myghty, map, paths, environ_config=None,
+ def __init__(self, tmpl_options, map, paths, environ_config=None,
default_charset='UTF-8', strict_c=False):
if environ_config is None:
environ_config = {}
- self.myghty = myghty
- self.template_options = {}
+ self.myghty = tmpl_options
+ self.template_options = tmpl_options
self.map = map
self.paths = paths
self.environ_config = environ_config
self.default_charset = default_charset
self.strict_c = strict_c
- if 'output_encoding' not in myghty:
- myghty['output_encoding'] = default_charset
+ if 'output_encoding' not in tmpl_options:
+ tmpl_options['output_encoding'] = default_charset
self.global_conf = {}
self.app_conf = {}
self.template_engines = []
+ self._clean_tmpl_options()
+
+ def _clean_tmpl_options(self):
+ """Prase the template options, set self.myghty to have myghty options
+ with no prefix and template_options to be a proper set of options for
+ any template engine"""
+ oldopts = self.myghty
+ self.template_options = {}
+ self.myghty = {}
+ for k, v in oldopts.iteritems():
+ if not re.match(r'\w+\.\w*', k):
+ self.myghty[k] = v
+ elif k.startswith('myghty.'):
+ self.myghty[k[7:]] = v
+ else:
+ self.template_options[k] = v
def add_template_engine(self, engine, root, options=None, alias=None):
"""Add additional template engines for configuration on Pylons WSGI init
@@ -192,7 +209,7 @@ def init_app(self, global_conf, app_conf, package, template_engine='pylonsmyghty
myghty_defaults['raise_error'] = True
myghty_defaults['component_root'] = [{os.path.basename(path): path} \
for path in self.paths['templates']]
-
+
# Merge in the user-supplied Myghty values
myghty_defaults.update(self.myghty)
@@ -215,6 +232,7 @@ def init_app(self, global_conf, app_conf, package, template_engine='pylonsmyghty
# Legacy copy of session and cache settings into app_conf
if k.startswith('session_') or k.startswith('cache_'):
self.app_conf[k] = v
+
if 'session_data_dir' not in app_conf:
app_conf['session_data_dir'] = os.path.join(app_conf['cache_dir'],
@@ -224,18 +242,26 @@ def init_app(self, global_conf, app_conf, package, template_engine='pylonsmyghty
'cache')
# Setup the main template options dict
- self.template_options = opts = myghty_template_options
-
+ self.template_options.update(myghty_template_options)
+
+ # Setup several defaults for various template languages
+ defaults = {}
+
# Rearrange template options as default for Mako
- opts['mako.directories'] = self.paths['templates']
- opts['mako.filesystem_checks'] = True
+ defaults['mako.directories'] = self.paths['templates']
+ defaults['mako.filesystem_checks'] = True
+ defaults['mako.output_encoding'] = self.default_charset
if 'cache_dir' in app_conf:
- opts['mako.module_directory'] = os.path.join(app_conf['cache_dir'],
+ defaults['mako.module_directory'] = os.path.join(app_conf['cache_dir'],
'templates')
# Setup kid defaults
- opts['kid.assume_encoding'] = 'utf-8'
- opts['kid.encoding'] = 'utf-8'
+ defaults['kid.assume_encoding'] = 'utf-8'
+ defaults['kid.encoding'] = self.default_charset
+
+ # Merge template options into defaults
+ defaults.update(self.template_options)
+ self.template_options = defaults
# Prepare our default template engine
if template_engine == 'pylonsmyghty':
@@ -16,14 +16,13 @@ def load_environment(global_conf={}, app_conf={}):
'static_files': os.path.join(root_path, 'public')
}
- # The following options are passed directly into Myghty, so all configuration options
- # available to the Myghty handler are available for your use here
- myghty = {}
- myghty['log_errors'] = True
- myghty['escapes'] = dict(l=webhelpers.auto_link, s=webhelpers.simple_format)
+ # The following template options are passed to your template engines
+ tmpl_options = {}
+ tmpl_options['myghty.log_errors'] = True
+ tmpl_options['myghty.escapes'] = dict(l=webhelpers.auto_link, s=webhelpers.simple_format)
- # Add your own Myghty config options here, note that all config options will override
+ # Add your own template options config options here, note that all config options will override
# any Pylons config options
# Return our loaded config object
- return pylons.config.Config(myghty, map, paths)
+ return pylons.config.Config(tmpl_options, map, paths)
@@ -23,8 +23,9 @@ def load_environment(global_conf={}, app_conf={}):
'templates': [os.path.join(root_path, 'templates')],
'static_files': os.path.join(root_path, 'public')
}
- myghty = dict(log_errors=True)
- return pylons.config.Config(myghty, map, paths)
+ tmpl_options = {}
+ tmpl_options['myghty.log_errors'] = True
+ return pylons.config.Config(tmpl_options, map, paths)
class Globals(object):
def __init__(self, global_conf, app_conf, **extra):

0 comments on commit 6bd88a1

Please sign in to comment.