Loading ...
Sorry, an error occurred while loading the content.

Re: [Cheetahtemplate-discuss] syntax extension to allow expressions in ${placeholders}: ${a*40} instead of using #echo $a*40

Expand Messages
  • Shannon -jj Behrens
    ... It d be nice to have defs act as generators per a compiler option (so that Cheetah could be used for streaming). Remember, though, that to meet your needs,
    Message 1 of 6 , Dec 15, 2005
    • 0 Attachment
      On 12/13/05, Mike Orr <sluggoster@...> wrote:
      > On 12/12/05, Tavis Rudd <tavis@...> wrote:
      > > in hindsight, it's a mystery to me why we didn't support this syntax instead
      > > of #echo in the first place.
      >
      > I've been using TurboGears recently and trying to reconcile myself to
      > Kid. One of the good things about Kid is this placeholder-expression
      > syntax, which is why I suggested it to Tavis. It's intutive and
      > avoids #echo's clutter.
      >
      > Another thing I like about Kid is extensive use of <?python ?>,
      > equivalent to Cheetah's <% %>, especially for setting local variables
      > (#set), import (#import), etc. So I think we made a mistake
      > discouraging <% %> and adding all these Python-equivalent directives.
      > Tavis disagrees with this assessment, however. :)
      >
      > The thing about Kid that drives me up the wall is burying control
      > structures in XML attributes where they're hard to find:
      >
      > <div py:for="r in mylist" class="row" attribute="value">
      >
      > vs
      >
      > #for $r in $mylist
      > <div class="row" attribute="value">
      >
      > Worse, Kid has no if/else construct, so you have to do two separate if's.
      >
      > So I was looking for a way to make a Cheetah derivative that took
      > Kid's good features but kept directives for #for/#if/#def/#while.
      > That was one of the reasons for Tavis's changes yesterday, making it
      > easier to create Cheetah derivatives with special default compiler
      > settings.
      >
      > One other Kid feature I'm trying to integrate is smart HTML escaping,
      > where the filter escapes any value that hasn't been wrapped in a
      > special string class (htmltext). The strategy published in my LG
      > article does most of it
      > http://linuxgazette.net/117/orr.html
      > and it's what I'm using now. But it requires setting #filter in every
      > template or passing the filter to every Template constructor.
      > Yesterday's change should make it easier to use a Template subclass
      > with an alternate filter as default. There's still one piece missing:
      > #def output. I haven't been using #def recently, otherwise I would
      > have noticed it right away. #def is used to build HTML snippets, and
      > of course these should automatically be trusted. But that should be
      > done by the #def itself, which means (1) having a standard htmltext
      > class in Cheetah, (2) working around #def using streaming output
      > (.write()) rather than 'return',

      It'd be nice to have defs act as generators per a compiler option (so
      that Cheetah could be used for streaming).

      Remember, though, that to meet your needs, you can return a subclass
      of str or unicode that has a "alreadyEscaped" attribute. You don't
      *have* to switch to streaming.

      > and (3) supporting both str and
      > unicode. Kid, PTL, and QPY [1] all have smart HTML escaping and thus
      > serve as reference code.
      >
      > [1] QPY is a reimplementation of PTL, and is distributed standalone.
      > http://www.mems-exchange.org/software/qpy/
      >
      > TurboGears will likely be going to a plugin architecture for
      > templates, so that Kid would be the default plugin but you could add
      > others. I'm working on that now.
      >
      > As for filter arguments ( ${foo, maxlen=40} ), I don't think they've
      > been used much if at all. I don't see what advantage they have over
      > regular functions ( $maxlen($foo, 40) ). So maybe we should drop
      > them.

      Best Regards,
      -jj

      --
      Law is much too important a thing to leave to politicians, lawyers,
      and celebrities.


      -------------------------------------------------------
      This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
      for problems? Stop! Download the new AJAX search engine that makes
      searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
      http://ads.osdn.com/?ad_idv37&alloc_id865&op=click
      _______________________________________________
      Cheetahtemplate-discuss mailing list
      Cheetahtemplate-discuss@...
      https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
    Your message has been successfully submitted and would be delivered to recipients shortly.