David Bernard wrote:
If it could help you, I copy/paste a fragment of my widgetform
generator, I use it instead of text string for widget's template :

from formencode.htmlgen import html as T

        back = T.form(name="f_"+self.key, action="save", method="post",
onsubmit="return validateForm(this)")(
                T.div(id="f_" + self.key + "_errors_",
class_="formFieldErrors")(
                    T.span(py__if="not(f_" + self.key + "_errors_ is
None)", py__replace="str(f_" + self.key + "_errors_)")
                ),

                ...,

                T.div(id="f_" + self.key + "_actions_",
class_="formActions")(
                    T.button(type="reset", id="btn_reset",
name="btn_reset")("reset"),
                    T.button(type="submit", id="btn_save",
name="btn_save")("save")
                ),
            )

advantage : formencode is already part of TG
Well, that's a *bit* of an advantage, but not an overwhelming one to me (if it were, I'd just use Kid ;-) I'm more interested in how clean and easy my templates are going to be. Especially since installing TurboStan is as easy as "easy_install TurboStan". I'll have to keep going to see if formencode is truly the equivalent of Stan (which if it *is* will give me somewhat mixed feelings, I'm sure you'll understand :-P )

Some things I like about Stan:
1) Clever use of subscripts makes for clean syntax.
2) Easy to extend (note my post that started this thread: I've already added 'include' and 'kid' tags with little effort, and these are on the more complicated end of tags you would want to create). 3) Multiple ways of expressing markup: Stan, raw XML, Nevow templates (although I prefer just Stan myself). 4) Very well tested. Stan is core to twisted.web and I'm confident in its efficiency and stability.

Also, as a minor nit, I personally chose to implement TurboStan templates as pure expressions. That is, there is no "import" or assignment within the template itself. While this does impose minor limitations on what you can express directly within the template, my personal feeling is that stuff shouldn't be in a template to begin with. While this could also be done with formencode, we're back to the "it's already been done" point, this time in TurboStan's favor ;-)

note the attribue py__if converted to html attribute py:if used by Kid
Out of curiosity, is this conversion done by formencode, Kid, or is this something you've added? Also, which documentation are you using for widgets? I'm planning on wrestling with them next and I'm looking for a good starting point. Some of the docs for the newer features are (understandably) scattered.

Regards,
Cliff



Reply via email to