RE: how to write custom tag in skunkweb? - how to register the tag?
"Ren Bing" <[email protected]>
| Newsgroups | gmane.comp.web.skunkweb |
|---|---|
| Message-ID | <[email protected]> |
Dear all, Many thanks for the information, I think I can figure out how to write a custom (at least simple ones) tag from checking the existing ones. However, there's still one question: how to register my custom tag to the system, so that it can be used in the STML? Shall I register it somewhere or shall I put it into some specific packages? Thanks. Bing Ren -----Original Message----- From: [email protected] [mailto:[email protected]]On Behalf Of Jacob Smullyan Sent: Friday, September 10, 2004 10:21 PM To: Ren Bing Cc: [email protected] Subject: Re: [Skunkweb-list] how to write custom tag in skunkweb? On Thu, 2004-09-09 at 22:18, Ren Bing wrote: > Dear all: > > I really appreciate someone show me how to write a custom tag in skunkweb? There isn't any documentation about this, unfortunately, so your best bet for understanding it is to look at some simple tags and see how they are implemented. SkunkWeb/Services/templating/ArgsTag.py is a good example that has all the features you need to think about, probably. The basic idea is that you subclass DT.Tag and implement the genCode() method, which writes Python code to an output stream. The tricky bit is the way that you marshal the tag arguments. There are two functions in DT.DTCompilerUtil, pyifyArgs and pyifyKWArgs, that are used for this; frankly I find these functions a bit confusing, but if you play with them you'll get the idea. (Roughly speaking, pyifyArgs returns a dictionary where the values are in effect repr'ed, and pyifyKWArgs returns the representation of a dictionary.) When you write the output, you have to be careful about indentation; the current indent is passed to genCode() as a parameter. Some STML tags, including ArgsTag, are implemented using temporary variables and inlining a lot of code that could be put in a function. I would suggest avoiding that, and making a tag as thin a wrapper around a function call as you can. If you are writing a block tag, you may want to override parseBlock(). STML has a "hidden namespace" called "__h" and a "temporary namespace" called "__t". Temporary variables are assigned to __t, and imports go in __h. If you need a module in a tag, put it in the tag's modules attribute in your constructor. I'm working on a new implementation of STML that makes it a bit easier to write tags; it can be found at http://stoat.smullyan.org/. Stoat STML supports importing tag libraries at runtime, makes it easier to only permit certain tags in specific contexts, and makes marshalling tag arguments easier. However, it is a slightly different dialect of STML, isn't yet integrated with skunkweb, and is still pre-alpha and subject to change. I hope that helps, js > Thanks! > > > Bing Ren > > > > ------------------------------------------------------- > This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170 > Project Admins to receive an Apple iPod Mini FREE for your judgement on > who ports your project to Linux PPC the best. Sponsored by IBM. > Deadline: Sept. 13. Go here: http://sf.net/ppc_contest.php > _______________________________________________ > Skunkweb-list mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/skunkweb-list > ------------------------------------------------------- This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170 Project Admins to receive an Apple iPod Mini FREE for your judgement on who ports your project to Linux PPC the best. Sponsored by IBM. Deadline: Sept. 13. Go here: http://sf.net/ppc_contest.php _______________________________________________ Skunkweb-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/skunkweb-list ------------------------------------------------------- This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170 Project Admins to receive an Apple iPod Mini FREE for your judgement on who ports your project to Linux PPC the best. Sponsored by IBM. Deadline: Sept. 13. Go here: http://sf.net/ppc_contest.php