pombreda / formalchemy

Automatically exported from code.google.com/p/formalchemy
MIT License
0 stars 0 forks source link

I suggest to add global configure feature to formalchemy #65

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

I suggest to add global configure feature to formalchemy, by example to
avoid this issue :

http://groups.google.fr/group/formalchemy/browse_thread/thread/346eaa20264dcbf5

This global configure can by example configure :

* template engine selection tempita or mako
* input_encoding
* output_encoding

formalchemy/__init__.py can define standard configuration value in config
variable.

One application can configuration FA with this command :

from formalchemy import config

config['template_engine'] = 'mako'
config['output_encoding'] = 'utf-8'

I've join my config feature implementation.

I this patch, I've extract tempita template to
formalchemy/templates/tempita_templates/

In my code, I don't like this part in formalchemy/templates/__init__.py:

# -*- coding: utf-8 -*-
import os
from formalchemy import config

__all__ = ['template_render']

# This class is used to load template_render function of template engine
# selected only when render function is called (example by FieldSet._render
# static method)
class __TemplateRender(object):
    def __init__(self, template_name):
        self.template_name = template_name

    def __call__(self, **kwargs):
        if config["template_engine"] == "tempita":
            from tempita_templates import template_render as
tempita_template_render
            return tempita_template_render(self.template_name)(**kwargs)
        elif config["template_engine"] == "mako":
            from mako_templates import template_render as mako_template_render
            return mako_template_render(self.template_name)(**kwargs)

def template_render(template_name):
    return __TemplateRender(template_name)

If your are better solution, I take :)

Regards,
Stephane

Original issue reported on code.google.com by klein.stephane on 15 Feb 2009 at 9:36

Attachments:

GoogleCodeExporter commented 9 years ago
We need a global config but i like to see it as a (fake ?) module to be able to
set/get the configuration options with attributes instead of keys.

Another good idea is to provide a way to configure FA with a paste 
configuration.
Like beaker do in pylons:

beaker.session.key = pylonsapp
beaker.session.secret = somesecret

For formalchemy we can have:

formalchemy.encoding = utf-8
formalchemy.template_engine = tempita

i also like to see something like this as a template engine wrapper:

config.template_engine = MakoTemplate(output_encoding='utf-8',
                                      **other_specific_engine_options)

then:

config.template_engine.render(template_name, **kwargs)

If you want to write a patch for this, be aware that the output is unit tested 
with
Tempita *and* mako. We want to test both.

Original comment by gael.pas...@gmail.com on 20 Feb 2009 at 12:42

GoogleCodeExporter commented 9 years ago
I've implemented all of this

Original comment by gael.pas...@gmail.com on 21 Feb 2009 at 6:07