Kevin Dangoor <[EMAIL PROTECTED]> writes:
> The move to Genshi is actually pretty easy, typically. (It may even
> be somewhat automatable, thanks to XML).
>
> Genshi's error handling, speed, text templates, extra tags, etc. make
> it a win that's worth pushing to sooner than later. SQLAlchemy's a
> big win as well, but it's a much more involved transition.
If we have a standard and easy way to push objects into the template then this
would be easily doable since Genshi lacks the <?python?> block. It would also
be great because it would be easier to remove code from Kid as well.
Imagine the following inside the master template:
<?python
import datetime
from turbogears.i18n.format import format_date
?>
<html ...>
<head>
...
</head>
<body>
<div class="header">
User ${tg.identity.display_name} -- ${format_date(datetime.now(),
format=long)}
</div>
</body>
</html>
If one wants to remove the imports and the call to datetime.now() those should
be made available for each and every template by default. Adding them to the
globally available variables isn't trivial / documented. It is doable (see
sample code below) but...
from turbogears.i18n.format import format_date
def var_updater(d):
d['today'] = format_date(datetime.now(), format='long')
turbogears.view.variable_providers.append(var_updater)
And then the template would be ...
<html ...>
<head>
...
</head>
<body>
<div class="header">
User ${tg.identity.display_name} -- ${today}
</div>
</body>
</html>
If we had a "view_globals.py" file that had its content inserted into the view
namespace "by default", then all functions and python code that one inserts
into templates could go there and be made available to any template engine
automatically.
Is it doable? Is it bad practice? Am I reinventing the wheel / doing things
the harder way?
Anyway, with that we wouldn't need the template engine to implement a python
wrapper to have it to use Python code (even if we have to disguise it). ;-)
Be seeing you,
--
Jorge Godoy <[EMAIL PROTECTED]>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---