Kenneth McDonald wrote:
> I have a homemade HTML generating library (something like HTMLgen) that 
> lets me do things like:
> 
> markup = str(DIV(SPAN("Hello"), SPAN("World"))
> 
> I'd like to use this at times in place of Kid files, but still keep a 
> clean separation of the sort provided by Kid files.
> 
> One possibility is simply to do something like this in a Kid file
> 
> <?python
> markup = ...some python code...
> ?>
> 
> ${markup}
> 
> 
> However, that doesn't give me the benefits provided by a python editor 
> unless I comment out the non-python markup, and somehow fool my editor 
> into thinking that a .kid file is actually a .py file.
> 
> Is there something like
> 
> @expose(python_template="my_python_code")
> 
> that would run a python code file to generate markup, rather than 
> processing a Kid file?

Yes.  TurboGears supports what is known as Buffet.  Any template engine 
that also supports that API can be easily used with TG (including yours).

You can find info about creating a Buffet adapter for your engine here:

http://projects.dowski.com/projects/buffet

If I were you I'd start by looking at the code for the simplest possible 
engine, StringTemplate and using that as a foundation for your code:

http://projects.dowski.com/view/buffetstring

Once you've created your adapter you can simply use:

@expose ( 'myengine:mytemplate' )
...

assuming you've registered your engine under the name 'myengine' (which 
I don't think I'd recommend ;-)



Another option is to simply return a string from your controller:

@expose ( )
def index ( self, *args, **kw ):
     markup = render_template ( )
     return markup

You may need to set some CherryPy response headers if you do this.

Regards,
Cliff

--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"TurboGears" 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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to