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

Re: [Cheetahtemplate-discuss] Re: Filters

Expand Messages
  • mso@oz.net
    ... OK, I d never heard of partial() before, but it s at http://python.org/peps/pep-0309.html and slated for 2.5. ... No, except inside arguments. $foo[$a
    Message 1 of 11 , Jul 29, 2005
      Ian Bicking wrote:
      >> I don't understand what you mean by "could be a function call" and
      >> "partial-evaluation" thing. It would have to be a callable, no?

      > Since #filter output (presumably) just passes a single argument, if you
      > want multiple arguments you might have to create partially-evaluated
      > forms. The proposed "partial()" builtin is for this, but in lieu of
      > that you can do it manually like with that indent() implementation.

      OK, I'd never heard of partial() before, but it's at
      http://python.org/peps/pep-0309.html
      and slated for 2.5.

      >>> $var|html

      >> Reminds me of Smarty modifiers. At least they are regular functions
      >> rather than the special builtins Smarty has. I'm not fond of these, but
      >> they would get at something #filter is clumsy at; namely, filtering
      >> individual placeholders scattered around a document while not filtering
      >> those in between. You don't want lots of #filter/#end filter all over
      >> the
      >> document.

      > I think it's reasonable that it has to be inside placeholders. Can
      > placeholders hold arbitrary expressions? If they can, then this would
      > work now.

      No, except inside arguments.
      $foo[$a +1]($bar + 1)
      ${foo[$a + 1]($bar + 1)}

      To output an expression directly, use #echo.
      #echo $a + 1
      The answer is #echo $a + 1#

      The syntax with braces is called "long syntax", and you can substitute $[]
      or $() if you prefer.

      >> One feature that is underused is filter arguments. In these examples,
      >> maxlen is an argument for the filter.
      >>
      >> #filter MaxLen
      >> ${placeholderName, maxlen=20}
      >> ${functionCall($functionArg), maxlen=$myMaxLen}
      >>
      >> Perhaps these could be pressed into service somehow, in conjunction with
      >> a
      >> more robust filter.
      >
      > It seems like this could potentially replace many uses of filter, like:
      > ${var|maxlen(20)}

      Yes indeed. We've talked about making a Superfilter that would have all
      sorts of arguments that do nifty things, a la Zope DTML's modifiers, but a
      spec was never designed. It's one of those low-priority projects that
      stagnated.

      --
      -- Mike Orr <mso@...>



      -------------------------------------------------------
      SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
      from IBM. Find simple to follow Roadmaps, straightforward articles,
      informative Webcasts and more! Get everything you need to get up to
      speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
      _______________________________________________
      Cheetahtemplate-discuss mailing list
      Cheetahtemplate-discuss@...
      https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
    • Shannon -jj Behrens
      ... ... By the way, Perl Mason has this feature. For instance, here s how to call a function like gettext (that s in a module /l10n.mas).
      Message 2 of 11 , Aug 3 10:02 PM
        > #call isn't great. "#filter" makes sense, but "#filter output" is a
        ...

        By the way, Perl Mason has this feature. For instance, here's how to
        call a function like gettext (that's in a module /l10n.mas).

        <&| /l10n.mas &>Translate this!</&>

        Notice that "Translate this!" can have all kinds of Mason stuff,
        whereas a function parameter in double quotes can't. Sure, you can
        always create another Cheetah method, but sometimes creating the
        function parameter inline using Cheetah syntax is really convenient.

        I've always had it on my TODO list to add this to Cheetah. I guess
        you can say it's like Ruby's blocks. It's a really helpful thing to
        have a templating language like Cheetah or Mason.

        Best Regards,
        -jj

        --
        I have decided to switch to Gmail, but messages to my Yahoo account will
        still get through.


        -------------------------------------------------------
        SF.Net email is Sponsored by the Better Software Conference & EXPO
        September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
        Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
        Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
        _______________________________________________
        Cheetahtemplate-discuss mailing list
        Cheetahtemplate-discuss@...
        https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
      • Ian Bicking
        ... My eyes, my eyes! Actually, it s my fingers that hurt when they imagine writing . Maybe that kind of stuff flies off Perl programmers
        Message 3 of 11 , Aug 3 10:49 PM
          Shannon -jj Behrens wrote:
          >>#call isn't great. "#filter" makes sense, but "#filter output" is a
          >
          > ...
          >
          > By the way, Perl Mason has this feature. For instance, here's how to
          > call a function like gettext (that's in a module /l10n.mas).
          >
          > <&| /l10n.mas &>Translate this!</&>

          My eyes, my eyes!

          Actually, it's my fingers that hurt when they imagine writing <&|
          /l10n.mas &>. Maybe that kind of stuff flies off Perl programmers'
          fingers, though. They must all be really good at touchtyping the first row.

          > Notice that "Translate this!" can have all kinds of Mason stuff,
          > whereas a function parameter in double quotes can't. Sure, you can
          > always create another Cheetah method, but sometimes creating the
          > function parameter inline using Cheetah syntax is really convenient.

          I thought about translation too, but it's a funny case -- translation
          has to happen before substitution. It actually kind of makes sense as a
          preprocessor; maybe one that creates multiple implementations of a
          method based on the language.

          > I've always had it on my TODO list to add this to Cheetah. I guess
          > you can say it's like Ruby's blocks. It's a really helpful thing to
          > have a templating language like Cheetah or Mason.

          The thing I was proposing -- which wouldn't work here -- would invoke
          the command after substitution occurred. So that's just another call
          syntax, not a macro or blog. Well, I think I floated the idea a
          callback would be passed in instead of the rendered result; which is
          like Ruby's blocks, but not the kind of macro that translation requires
          (since blocks/functions are opaque, and translations really want to work
          on a source level).

          Incidentally, Plone is popular in large part (very large part) because
          of its internationalization. So that's the kind of thing that can
          attract a very strong following. But I actually don't know if ZPT has
          any internationalization features; I feel like it happens at a different
          level. Of course acquisition gives them the ability to inject
          alternative implementations just about anywhere in Zope, for good in
          this case (but bad everywhere else ;), so maybe they don't need it at
          the template level.

          --
          Ian Bicking / ianb@... / http://blog.ianbicking.org


          -------------------------------------------------------
          SF.Net email is Sponsored by the Better Software Conference & EXPO
          September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
          Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
          Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
          _______________________________________________
          Cheetahtemplate-discuss mailing list
          Cheetahtemplate-discuss@...
          https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
        • Shannon -jj Behrens
          ... hehehe Yes, after a while, believe it or not, typing that stuff does fly off the fingers. Understand, however, that I was a Python fan throughout that
          Message 4 of 11 , Aug 4 3:50 PM
            On 8/3/05, Ian Bicking <ianb@...> wrote:
            > Shannon -jj Behrens wrote:
            > >>#call isn't great. "#filter" makes sense, but "#filter output" is a
            > >
            > > ...
            > >
            > > By the way, Perl Mason has this feature. For instance, here's how to
            > > call a function like gettext (that's in a module /l10n.mas).
            > >
            > > <&| /l10n.mas &>Translate this!</&>
            >
            > My eyes, my eyes!
            >
            > Actually, it's my fingers that hurt when they imagine writing <&|
            > /l10n.mas &>. Maybe that kind of stuff flies off Perl programmers'
            > fingers, though. They must all be really good at touchtyping the first row.

            hehehe

            Yes, after a while, believe it or not, typing that stuff does fly off
            the fingers. Understand, however, that I was a Python fan throughout
            that whole work experience.

            > > Notice that "Translate this!" can have all kinds of Mason stuff,
            > > whereas a function parameter in double quotes can't. Sure, you can
            > > always create another Cheetah method, but sometimes creating the
            > > function parameter inline using Cheetah syntax is really convenient.
            >
            > I thought about translation too, but it's a funny case -- translation
            > has to happen before substitution. It actually kind of makes sense as a
            > preprocessor; maybe one that creates multiple implementations of a
            > method based on the language.

            In a sense, you've called my bluff. The actual code was:

            <&| /l10n.mas, bind => [$count] &>
            [*,_1,document was,documents were] matched.
            </&>

            Notice that that is an example that supports plurality. Anyway, as
            always l10n is a deep subject.

            (I was responsible for l10n in that project as well as at my current
            company, so I feel comfortable talking about this subject.)

            > > I've always had it on my TODO list to add this to Cheetah. I guess
            > > you can say it's like Ruby's blocks. It's a really helpful thing to
            > > have a templating language like Cheetah or Mason.
            >
            > The thing I was proposing -- which wouldn't work here -- would invoke
            > the command after substitution occurred.

            What was really crazy about Mason was that it indeed worked like a
            callback, and one would often make use of $_ using dynamic scoping.
            Here's an example:

            <table>
            <tr>
            <th>Part Number</th>
            ...
            </tr>

            <&| /db/order_items:exec, bind => [$order_id] &>
            <tr>
            <td><% $_->{partnum} %></td>
            ...
            </tr>
            </&>
            </table>

            Basically, /db/order_items is a file that contains nothing more than a
            SQL query. However, it implicitly subclasses /db/autohandler, which
            has an exec method. That exec method executes the query in
            /db/order_items and loops over the results. On each loop iteration,
            it sets $_. Then it "calls the callback", which makes use of $_ as
            you can see above. Yes, crazy. It's Perl. Nonetheless, it was
            wickedly cool and convenient.

            > So that's just another call
            > syntax, not a macro or blog.

            Yes, it's the syntax for calling a function and passing a block that
            I'm interested in. I think the feature is similar in Mason and Ruby.

            > Well, I think I floated the idea a
            > callback would be passed in instead of the rendered result; which is
            > like Ruby's blocks, but not the kind of macro that translation requires
            > (since blocks/functions are opaque, and translations really want to work
            > on a source level).

            Agreed. That's why in the example above, stuff substituted in was
            passed as arguments.

            > Incidentally, Plone is popular in large part (very large part) because
            > of its internationalization.

            Yeah, I'm reading the Plone book now, so I've learned how all of that
            works. I haven't yet seen anything that blows my mind more than the
            way I use to do it in Mason. Realistically, in Cheetah, I often end
            up doing things like:

            $str($_("""\
            The policy '%s' was deleted.
            blah
            blah""") % name)

            It's easy to imagine something better. Strawman proposal:

            #call _((name,))
            The policy '%s' was deleted.
            blah
            blah
            #end call

            (Note, the unindent is intentional because I don't want the whitespace
            in the translation catalog, but I do want to control what whitespace
            does make it into the translation catalog.)

            I think such a feature would be a good fit for Cheetah. Furthermore,
            gettext would just be one of many good uses for this feature.

            > So that's the kind of thing that can
            > attract a very strong following. But I actually don't know if ZPT has
            > any internationalization features; I feel like it happens at a different
            > level. Of course acquisition gives them the ability to inject
            > alternative implementations just about anywhere in Zope, for good in
            > this case (but bad everywhere else ;), so maybe they don't need it at
            > the template level.

            Practically speaking, to support I18N in gettext style, you basically
            need these things:

            1. A way to pass a large string to the gettext function.

            2. A way to format the source code so that a program can scan it for
            translatable strings that can be put into the translation catalog.

            Of course, l10n being what it is, I'm sure I've way oversimplified things ;)

            Happy Hacking,
            -jj

            --
            I have decided to switch to Gmail, but messages to my Yahoo account will
            still get through.


            -------------------------------------------------------
            SF.Net email is Sponsored by the Better Software Conference & EXPO
            September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
            Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
            Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
            _______________________________________________
            Cheetahtemplate-discuss mailing list
            Cheetahtemplate-discuss@...
            https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
          • Tavis Rudd
            Hi, if there aren t any bug reports about the new caching code (in the cvs) before next Tuesday, I m going to cut a new release and update the Users Guide
            Message 5 of 11 , Aug 5 2:21 PM
              Hi,
              if there aren't any bug reports about the new caching code (in the cvs) before
              next Tuesday, I'm going to cut a new release and update the Users Guide
              install section with a note about namemapper and windows.
              Cheers,
              Tavis


              -------------------------------------------------------
              SF.Net email is Sponsored by the Better Software Conference & EXPO
              September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
              Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
              Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
              _______________________________________________
              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.