Sounds like a good idea to me.  I'm all for it, as this is definitely
a common needs, and in theory all common config changes should he
handled declaratively and not require overiding methods on AppConfig.

--Mark

On Mon, Sep 8, 2008 at 11:11 AM, lmacken <[EMAIL PROTECTED]> wrote:
>
> Hey everyone,
>
> I'm attaching a patch that adds an 'auto_reload_templates'
> configuration option to the tg2 AppConfig object.  At the moment, if
> you wish to disable template auto-reloading for your production
> applications, it requires doing something like this in your app_cfg:
>
>    class MyConfig(AppConfig):
>
>        def setup_genshi_renderer(self):
>            from genshi.template import TemplateLoader
>            from tg.render import render_genshi
>            def template_loaded(template):
>                genshi.template.filters.insert(0,
> Translator(ugettext))
>            config['pylons.app_globals'].genshi_loader =
> TemplateLoader(
>                self.paths['templates'], auto_reload=False)
>            self.renderer_functions = render_genshi
>
>        def setup_mako_renderer(self):
>            from mako.lookup import TemplateLookup
>            from tg.render import render_mako
>            config['pylons.app_globals'].mako_lookup = TemplateLookup(
>                directories=self.paths['templates'],
>                module_directory=self.paths['templates'],
>                input_encoding='utf-8', output_encoding='utf-8',
>                imports=['from webhelpers.html import escape'],
>                default_filters=['escape'], filesystem_checks=False)
>            self.render_functions.mako = render_mako
>
> Yes, it's trivial to copy/paste the existing setup methods, and tweak
> them a bit -- but the problem is that the variable to disable this
> feature differs between the various template engines.  With my
> proposed patch, disabling template auto-reloading becomes as simple as
> this:
>
>    base_config.auto_reload_templates = False
>
> Here is the patch.  I'd be glad to commit this if people think it's a
> good idea.
>
> Cheers,
>
> luke
>
> --- configuration.py    (revision 5362)
> +++ configuration.py    (working copy)
> @@ -112,7 +112,7 @@
>         self.auth_backend = None
>         self.serve_static = True
>         self.use_legacy_render = True
> -
> +        self.auto_reload_templates = True
>
>     def setup_paths(self):
>         root =
> os.path.dirname(os.path.abspath(self.package.__file__))
> @@ -181,10 +181,11 @@
>             module_directory=self.paths['templates'],
>             input_encoding='utf-8', output_encoding='utf-8',
>             imports=['from webhelpers.html import escape'],
> -            default_filters=['escape'])
> -
> +            default_filters=['escape'],
> +            filesystem_checks=self.auto_reload_templates)
> +
>         self.render_functions.mako = render_mako
> -
> +
>     def setup_genshi_renderer(self):
>         """Setup a renderer and loader for Genshi templates"""
>         from genshi.template import TemplateLoader
> @@ -194,7 +195,7 @@
>             "Plug-in our i18n function to Genshi."
>             genshi.template.filters.insert(0, Translator(ugettext))
>         loader = TemplateLoader(search_path=self.paths.templates,
> -                                auto_reload=True)
> +
> auto_reload=self.auto_reload_templates)
>
>         config['pylons.app_globals'].genshi_loader = loader
>
> @@ -206,7 +207,8 @@
>         from tg.render import render_jinja
>
>         config['pylons.app_globals'].jinja_env =
> Environment(loader=ChoiceLoader(
> -                [FileSystemLoader(path) for path in
> self.paths['templates']]))
> +                [FileSystemLoader(path,
> auto_reload=self.auto_reload_templates)
> +                 for path in self.paths['templates']]))
>         # Jinja's unable to request c's attributes without strict_c
>         config['pylons.strict_c'] = True
>
>
> >
>



-- 
Mark Ramm-Christensen
email: mark at compoundthinking dot com
blog: www.compoundthinking.com/blog

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears Trunk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears-trunk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to