Changeset 3319

Show
Ignore:
Timestamp:
07/19/07 13:42:55 (1 year ago)
Author:
chrisz
Message:

Ported r3287 and r3318 from 1.0 to 1.1 (changes for TurboKid? 1.0.2).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/setup.py

    r3176 r3319  
    1616        "TurboJson >= 0.9.9", 
    1717        "TurboCheetah >= 0.9.5", 
    18         "TurboKid >= 1.0.1", 
     18        "TurboKid >= 1.0.2", 
    1919        "Genshi >= 0.4.2", 
    2020        "SQLAlchemy >= 0.3.8", 
  • branches/1.1/turbogears/i18n/kidutils.py

    r2902 r3319  
    22Functions for use with Kid template 
    33""" 
    4 from kid.pull import START, TEXT, END 
     4from kid.parser import START, TEXT, END 
    55 
    66import turbogears 
     
    1010 
    1111def translate(item, attr=None): 
    12     """Translates the text of element plus the text of all child elements. If attr is present  
     12    """Translates the text of element plus the text of all child elements. If attr is present 
    1313    this is used to provide the locale name; if not then value provided by get_locale is used. 
    1414    For example: 
    15      
     15 
    1616    <div lang=""> 
    1717        this is a test 
    1818        <a href="de">testing</a> 
    1919    </div> 
    20      
    21     The string 'this is a test' is rendered by the locale provided by get_locale, the  
     20 
     21    The string 'this is a test' is rendered by the locale provided by get_locale, the 
    2222    string 'testing' by the German locale. 
    23      
     23 
    2424    Possible use in Kid template: 
    2525    <?python 
    2626    from turbogears.i18n import translate 
    2727    ?> 
    28     <translate xmlns:py="http://purl.org/kid/ns#" py:match="item.attrib.has_key('lang')"  
     28    <translate xmlns:py="http://purl.org/kid/ns#" py:match="item.attrib.has_key('lang')" 
    2929    py:replace="translate(item)"/> 
    3030    <h1 lang="">Welcome!</h1> 
     
    3333    @param attr: attribute name used to store locale, if any 
    3434    """ 
    35     if attr is None:attr = turbogears.config.get("i18n.templateLocaleAttribute", "lang")     
     35    if attr is None:attr = turbogears.config.get("i18n.templateLocaleAttribute", "lang") 
    3636    translate_all(item, item.get(attr), attr) 
    3737    return item 
     
    5454        tree.text = __translate_text(tree.text, lang) 
    5555    if tree.tail and not inroot: 
    56         # Don't translate tail of root. It is beyond the scope of the lang attr  
     56        # Don't translate tail of root. It is beyond the scope of the lang attr 
    5757        tree.tail = __translate_text(tree.tail, lang) 
    5858    for element in tree: 
     
    6262 
    6363def i18n_filter(stream, template, locale=None): 
    64     """Kid template filter which calls translates all elements matching language  
     64    """Kid template filter which calls translates all elements matching language 
    6565    attribute(set in configuration as i18n.templateLocaleAttribute, default 'lang') 
    6666    """ 
    67      
    68     lang_attr = turbogears.config.get("i18n.templateLocaleAttribute", "lang")     
     67 
     68    lang_attr = turbogears.config.get("i18n.templateLocaleAttribute", "lang") 
    6969    locales=[locale] 
    70      
     70 
    7171    for ev, item in stream: 
    72                  
    73         if ev==START:         
     72 
     73        if ev==START: 
    7474            l = item.get(lang_attr) 
    75             if l:     
     75            if l: 
    7676                locale = l 
    77                 locales.append(l)                 
     77                locales.append(l) 
    7878        elif ev==TEXT: 
    7979            prefix = '' 
     
    8181            if len(item) > 0 and item[0] == ' ': prefix =' ' 
    8282            if len(item) > 1 and item[-1] == ' ': postfix =' ' 
    83              
     83 
    8484            text = item.strip() 
    8585            if text: 
    86                 item = gettext(text, locale)      
     86                item = gettext(text, locale) 
    8787                item = prefix + item + postfix 
    8888        elif ev==END: 
     
    9090                locales.pop() 
    9191                locale = locales[-1] 
    92              
     92 
    9393        yield (ev, item) 
  • branches/1.1/turbogears/qstemplates/quickstart/+package+/config/app.cfg_tmpl

    r3174 r3319  
    3838# The following kid settings determine the settings used by the kid serializer. 
    3939 
    40 # One of (html|html-strict|xhtml|xhtml-strict|xml|json) 
    41 # kid.outputformat="html" 
     40# Kid output method (e.g. html, html-strict, xhtml, xhtml-strict, xml, json) 
     41# and formatting (e.g. default, straight, compact, newlines, wrap, nice) 
     42# kid.outputformat="html default" 
    4243 
    4344# kid.encoding="utf-8" 
     
    114115#if $identity=='sqlobject' 
    115116# identity.provider='${identity}' 
    116 #else  
     117#else 
    117118identity.provider='${identity}' 
    118 #end if  
     119#end if 
    119120 
    120121# The names of the fields on the login form containing the visitor's user ID 
     
    150151# form.  If you set the password through the password property, like: 
    151152# my_user.password = 'secret' 
    152 # the password will be encrypted in the database, provided identity is up and  
     153# the password will be encrypted in the database, provided identity is up and 
    153154# running, or you have loaded the configuration specifying what encryption to 
    154155# use (in situations where identity may not yet be running, like tests). 
    155156 
    156157# identity.soprovider.encryption_algorithm=None 
    157 #else  
     158#else 
    158159# SqlAlchemyIdentityProvider 
    159160# Configuration options for the default IdentityProvider 
     
    174175# form.  If you set the password through the password property, like: 
    175176# my_user.password = 'secret' 
    176 # the password will be encrypted in the database, provided identity is up and  
     177# the password will be encrypted in the database, provided identity is up and 
    177178# running, or you have loaded the configuration specifying what encryption to 
    178179# use (in situations where identity may not yet be running, like tests). 
     
    183184 
    184185# compress the data sends to the web browser 
    185 # [/]  
     186# [/] 
    186187# gzip_filter.on = True 
    187188# gzip_filter.mime_types = ["application/x-javascript", "text/javascript", "text/html", "text/css", "text/plain"] 
  • branches/1.1/turbogears/tests/test_controllers.py

    r3226 r3319  
    448448        turbogears.config.update({'kid.outputformat': 'xhtml'}) 
    449449        testutil.createRequest('/test') 
    450         assert '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML ' in cherrypy.response.body[0] 
     450        response = cherrypy.response.body[0] 
     451        assert '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML ' in response 
    451452        turbogears.config.update({'kid.outputformat': 'html'}) 
    452453        testutil.createRequest('/test') 
    453         assert  '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML ' in cherrypy.response.body[0] 
     454        response = cherrypy.response.body[0] 
     455        assert  '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML ' in response 
     456        assert '    This is the groovy test ' in response 
     457        turbogears.config.update({'kid.outputformat': 'html compact'}) 
     458        testutil.createRequest('/test') 
     459        response = cherrypy.response.body[0] 
     460        assert  '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML ' in response 
     461        assert 'This is the groovy test ' in response 
     462        assert '    ' not in response 
    454463 
    455464    def test_fileserving(self): 
  • branches/1.1/turbogears/view/base.py

    r3269 r3319  
    11"""Template processing for TurboGears view templates.""" 
    22 
    3 import os 
    4 import imp 
    53import sys 
    64import re 
     
    4341            if callable(value): 
    4442                dict[key] = print_warning(value) 
    45         return type.__new__(cls,name, bases, dict) 
     43        return type.__new__(cls, name, bases, dict) 
    4644 
    4745class DeprecatedVariableProviders(list): 
     
    9795 
    9896 
    99 def render(info, template=None, format=None ,content_type=None, mapping=None, fragment=False): 
     97def render(info, template=None, format=None, content_type=None, mapping=None, fragment=False): 
    10098    """Renders data in the desired format. 
    10199 
     
    126124    cherrypy.response.headers["Content-Type"] = content_type 
    127125    if not format: 
    128         format = config.get("%s.outputformat" % enginename, "html")  
     126        format = config.get("%s.outputformat" % enginename, "html") 
    129127    args, kw = adapt_call(engine.render, args= [], 
    130128                kw = dict(info=info, format=format, fragment=fragment, template=template, mapping=mapping), start=1) 
     
    172170    """ 
    173171    value = None 
    174     def __init__(self,iterable): 
     172    def __init__(self, iterable): 
    175173        self._cycle = icycle(iterable) 
    176174    def __str__(self): 
     
    344342def load_engines(): 
    345343    config = turbogears.config 
    346     engine_options =
     344    engine_options =
    347345        "mako.directories" : config.get("mako.directories", []), 
    348346        "mako.output_encoding" : config.get("mako.output_encoding", "utf-8"),