Hello Ryan-

Thanks for your response to integrating Kid with Webware. I think it would be quite easy to integrate Kid into Webware from what you have said in your email.

Regarding how to get a Kid template to be a WebKit servlet, Cheetah does some similar tricks to make it inherit from Servlet ONLY IF Webware is around, but not otherwise. But I think that is the wrong way to go. As some people have pointed out, sometimes you want your template to be a servlet, and other times you just want to call a template from your servlet. Also, interdependencies make testing difficult. Here's what I propose for how to get Kid into Webware. Make an option where you can specify a base class for your template. If it is not specified, then it defaults to Kid.BaseTemplate. Now the servlet engine that I write will have it's own class which extends both Kid.BaseTemplate, and WebKit.Page, I'll call it KidKit.TemplatePage. Any kid template that should be loaded as a servlet can extend KidKit. TemplatePage and now it has the capabilities of both. This way Kid doesn't have any dependency on WebKit, but user's pages will.

Perhaps it already has this extending feature, I haven't been able to get Kid running on my machine. If you could help me with my trouble running Kid, then I could write a ServletFactory for integrating Kid into Webware. I'll contact you outside the list.

-winston


On Jan 6, 2005, at 7:15 AM, Ryan Tomayko wrote:

Hi Tom / Webware-discuss,

I'm jazzed to see interest around Webware w/ Kid. I have very little experience with Webware myself but I'm committed to making any modifications necessary on the Kid side to ensure that it is easy to use in all popular python web environments.

On Fri, 31.12.2004, 11:20 -0500 Winston Wolf wrotef:
It looks very nice syntax wise. I'm wondering how to best use it in
Servlets though. Can you have a Kid template inherit from
WebKit.Page? If not, how would you use a kid template? The only way
I see right off the bat is to write a python servlet that includes the
Kid template. But that means writing a python class for every
template.

Here's some information on how kid templates work under the hood. Each kid template module exposes a class named "Template":

import kid
class Template(kid.BaseTemplate):
...

The kid.BaseTemplate class has methods for "executing" the template. This includes a `write` method that executes a template and writes output to a file like object, an 'encode' method that executes a template and returns the encoded XML output as a string, and a few other methods that allow a Kid template to work along a SAX pipeline.

So one possible option might be to have kid.BaseTemplate subclass WebKit.Page or a subclass of WebKit.Page. This would require some craftiness: WebKit.Page would have to be added to BaseTemplate.__bases__ dynamically based on whether WebKit was available. What I like about this approach is that all Kid templates would automatically be subclasses of WebKit.Page.

Does this approach seem viable?

On Sun, 02.01.2005, 16:59 -0500 Winston Wolff wrote:
So I'm wondering, is there a way to compile a Kid template into a
class, and then have another kid template inherit from that class,
extending just certain parts?

As I mentioned, all kid template modules automatically expose a class named Template. To illustrate this a bit further, consider having a file named "test_template.kid" somewhere on sys.path. The following python code would create an instance of the template class, execute it, and write output to stdout:

from test_template import Template
t = Template()
t.write(file=sys.stdout)

It should also be possible to subclass the Template class:

class TemplatePage(WebKit.Page, Template):
...

Again, I'm not familiar with WebKit.Page so I'm not positive this would be viable.

Personally I think is is worth the effort to write a first class KidKit (funny name!),
solving all this problems and enabling Webware beginners to put .kid files
into their directories and Webware doing all the magic, something I never understood
why Cheetah did not do (it was planned, but I have never seen it and people seem still
to ask for it). I like out of the box solutions! ;-)

Me too.

Right now I'm trying to get the basic template language sorted out; it's fairly close. I should be shifting my attention over to getting kid to run out-of-the-box on different web frameworks in the near future.

If anyone is thinking about taking a stab at this, know that your time would not be wasted. I'm committed to changing anything necessary with the base kid package to have things work smoothly with webware (and other web frameworks) and I'm also not against distributing add-on type functionality with the kid distribution.

I would *love* to have a few maintainers with access to kid cvs that would be able to add support for and/or track changes to different web frameworks to make sure kid is really easy to use under any web framework. If you happen to take a stab at getting Kid to work nicely with Webware, please consider sending over any patches, support files, or examples.

Thanks,
Ryan Tomayko



_________________________________________
winston wolff - (646) 827-2242 - http://www.stratolab.com - learning by creating

Reply via email to