Changeset 3319
- Timestamp:
- 07/19/07 13:42:55 (1 year ago)
- Files:
-
- branches/1.1/setup.py (modified) (1 diff)
- branches/1.1/turbogears/i18n/kidutils.py (modified) (7 diffs)
- branches/1.1/turbogears/qstemplates/quickstart/+package+/config/app.cfg_tmpl (modified) (5 diffs)
- branches/1.1/turbogears/tests/test_controllers.py (modified) (1 diff)
- branches/1.1/turbogears/view/base.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.1/setup.py
r3176 r3319 16 16 "TurboJson >= 0.9.9", 17 17 "TurboCheetah >= 0.9.5", 18 "TurboKid >= 1.0. 1",18 "TurboKid >= 1.0.2", 19 19 "Genshi >= 0.4.2", 20 20 "SQLAlchemy >= 0.3.8", branches/1.1/turbogears/i18n/kidutils.py
r2902 r3319 2 2 Functions for use with Kid template 3 3 """ 4 from kid.p ullimport START, TEXT, END4 from kid.parser import START, TEXT, END 5 5 6 6 import turbogears … … 10 10 11 11 def 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 13 13 this is used to provide the locale name; if not then value provided by get_locale is used. 14 14 For example: 15 15 16 16 <div lang=""> 17 17 this is a test 18 18 <a href="de">testing</a> 19 19 </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 22 22 string 'testing' by the German locale. 23 23 24 24 Possible use in Kid template: 25 25 <?python 26 26 from turbogears.i18n import translate 27 27 ?> 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')" 29 29 py:replace="translate(item)"/> 30 30 <h1 lang="">Welcome!</h1> … … 33 33 @param attr: attribute name used to store locale, if any 34 34 """ 35 if attr is None:attr = turbogears.config.get("i18n.templateLocaleAttribute", "lang") 35 if attr is None:attr = turbogears.config.get("i18n.templateLocaleAttribute", "lang") 36 36 translate_all(item, item.get(attr), attr) 37 37 return item … … 54 54 tree.text = __translate_text(tree.text, lang) 55 55 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 57 57 tree.tail = __translate_text(tree.tail, lang) 58 58 for element in tree: … … 62 62 63 63 def 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 65 65 attribute(set in configuration as i18n.templateLocaleAttribute, default 'lang') 66 66 """ 67 68 lang_attr = turbogears.config.get("i18n.templateLocaleAttribute", "lang") 67 68 lang_attr = turbogears.config.get("i18n.templateLocaleAttribute", "lang") 69 69 locales=[locale] 70 70 71 71 for ev, item in stream: 72 73 if ev==START: 72 73 if ev==START: 74 74 l = item.get(lang_attr) 75 if l: 75 if l: 76 76 locale = l 77 locales.append(l) 77 locales.append(l) 78 78 elif ev==TEXT: 79 79 prefix = '' … … 81 81 if len(item) > 0 and item[0] == ' ': prefix =' ' 82 82 if len(item) > 1 and item[-1] == ' ': postfix =' ' 83 83 84 84 text = item.strip() 85 85 if text: 86 item = gettext(text, locale) 86 item = gettext(text, locale) 87 87 item = prefix + item + postfix 88 88 elif ev==END: … … 90 90 locales.pop() 91 91 locale = locales[-1] 92 92 93 93 yield (ev, item) branches/1.1/turbogears/qstemplates/quickstart/+package+/config/app.cfg_tmpl
r3174 r3319 38 38 # The following kid settings determine the settings used by the kid serializer. 39 39 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" 42 43 43 44 # kid.encoding="utf-8" … … 114 115 #if $identity=='sqlobject' 115 116 # identity.provider='${identity}' 116 #else 117 #else 117 118 identity.provider='${identity}' 118 #end if 119 #end if 119 120 120 121 # The names of the fields on the login form containing the visitor's user ID … … 150 151 # form. If you set the password through the password property, like: 151 152 # 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 153 154 # running, or you have loaded the configuration specifying what encryption to 154 155 # use (in situations where identity may not yet be running, like tests). 155 156 156 157 # identity.soprovider.encryption_algorithm=None 157 #else 158 #else 158 159 # SqlAlchemyIdentityProvider 159 160 # Configuration options for the default IdentityProvider … … 174 175 # form. If you set the password through the password property, like: 175 176 # 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 177 178 # running, or you have loaded the configuration specifying what encryption to 178 179 # use (in situations where identity may not yet be running, like tests). … … 183 184 184 185 # compress the data sends to the web browser 185 # [/] 186 # [/] 186 187 # gzip_filter.on = True 187 188 # 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 448 448 turbogears.config.update({'kid.outputformat': 'xhtml'}) 449 449 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 451 452 turbogears.config.update({'kid.outputformat': 'html'}) 452 453 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 454 463 455 464 def test_fileserving(self): branches/1.1/turbogears/view/base.py
r3269 r3319 1 1 """Template processing for TurboGears view templates.""" 2 2 3 import os4 import imp5 3 import sys 6 4 import re … … 43 41 if callable(value): 44 42 dict[key] = print_warning(value) 45 return type.__new__(cls, name, bases, dict)43 return type.__new__(cls, name, bases, dict) 46 44 47 45 class DeprecatedVariableProviders(list): … … 97 95 98 96 99 def render(info, template=None, format=None ,content_type=None, mapping=None, fragment=False):97 def render(info, template=None, format=None, content_type=None, mapping=None, fragment=False): 100 98 """Renders data in the desired format. 101 99 … … 126 124 cherrypy.response.headers["Content-Type"] = content_type 127 125 if not format: 128 format = config.get("%s.outputformat" % enginename, "html") 126 format = config.get("%s.outputformat" % enginename, "html") 129 127 args, kw = adapt_call(engine.render, args= [], 130 128 kw = dict(info=info, format=format, fragment=fragment, template=template, mapping=mapping), start=1) … … 172 170 """ 173 171 value = None 174 def __init__(self, iterable):172 def __init__(self, iterable): 175 173 self._cycle = icycle(iterable) 176 174 def __str__(self): … … 344 342 def load_engines(): 345 343 config = turbogears.config 346 engine_options = {344 engine_options = { 347 345 "mako.directories" : config.get("mako.directories", []), 348 346 "mako.output_encoding" : config.get("mako.output_encoding", "utf-8"),