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

Re: [Cheetahtemplate-discuss] #indent reprise

Expand Messages
  • robert_kuzelj@yahoo.com
    hi mike, ... try that one. ... how can this be done? i havent had a clue. ... this one surely can be done easely. ... this would be even of greater benefit.
    Message 1 of 9 , Jun 10, 2002
    • 0 Attachment
      hi mike,

      > Did you send an attachment? I didn't receive it. I looked to see if
      > there was one, and figured that by "real code" you meant the example
      > in the text.
      try that one.

      > Filters *are* called only for placeholders but they *can* be called for
      > any string that wants to be formatted.
      how can this be done?
      i havent had a clue.

      > 1) Plug-in "directives" (the string substitution mentioned above).
      this one surely can be done easely.

      > 2) Plug-in directives (real directives that can do anything a Cheetah
      > directive can do). I'm not sure whether this is desirable. It would
      > give users the ability to link in their own directives. On the
      > other hand, it may be big to implement, and the quality-control
      > issues of allowing third-party directives would outweigh any
      > benefits. Another way to allow third-party directives would be
      > through a user-specified subclass of Parser, which Template would
      > use instead if given a parserClass argument.
      this would be even of greater benefit. cheetah could grow
      an enormous library of directives.

      ciao robertj



      ------------------------------------------------------------
      Robert Kuzelj
      Gaissacherstrasse 7 email: robert_kuzelj@...
      81371 Muenchen tel: 0177/5302230

      the trinity of desirables of (software) architecture:
      Firmitas, Utilitas, Venustas (marcus vitruvius 20 BC)
      strength, utility, beauty
    • Mike Orr
      ... By instantiating your own filter objects, or by calling $currentFilter -aka- self._currentFilter() [Tavis, shouldn t we have self.currentFilter() for
      Message 2 of 9 , Jun 11, 2002
      • 0 Attachment
        On Mon, Jun 10, 2002 at 01:22:05PM +0200, robert_kuzelj@... wrote:
        > > Filters *are* called only for placeholders but they *can* be called for
        > > any string that wants to be formatted.
        > how can this be done?
        > i havent had a clue.

        By instantiating your own filter objects, or by calling
        $currentFilter -aka- self._currentFilter()

        [Tavis, shouldn't we have self.currentFilter() for consistency with
        other mccessor ethods.]

        BTW, in your script, you don't need to set 'filtersLib' because
        that's already the default. You only need to set it if you want to
        use your own custom filter AND you want to specify it by name rather
        than passing in a class.

        ***
        Your implementation is quite intriguing and well done, especially
        how you have an 'if not match' to place $indent in front of all
        lines, even those that don't have an #indent directive. My comments:

        ** With some refactoring, one *may* be able to put it into Cheetah.Tools
        under the name IndentTemplate.py, and then templates could #extends it.
        But I think we'd have to put the preprocessor call somewhere else
        rather than __init__, since I think that unless it's a precompiled template,
        __init__ would already be executing/would have finished executing by the
        time the #extends is discovered. Perhaps Cheetah could have a
        .preProcess() hook that by default did nothing, but in your case it
        would modify the source string before the Parser/Compiler saw it.
        But then we'd want to make it also handle a pipeline of
        preprocessors too...

        ** Since indentation is something that any template could benefit from
        (including HTML/XML if you want the source to look nice, which is a
        plus), I'd be inclined to build #indent into Cheetah.
        At the cost of one more pass through the source if not used,
        we could do an initial search for '#indent', and if found anywhere,
        run the indentation processor on the source, then feed it to the
        Parser/Compiler. I'd say that would be preferable over building the
        structure into every portion of the compiler, although the compiler
        *could* insert the indentation spaces itself rather than a
        $indent call, since it's all known at compile time (right?).

        ** I wonder if #indent has too many argument options. What are they
        all?
        #indent on ## While the indenter is on, strip leading whitespace
        ## from source lines, and prepend '$indent__' to every
        ## line. (This will indent source lines but not
        ## continuation lines of multi-line placeholders.)
        #indent off ## Restore default behavior.
        #indent = EXPR ## Set indentation level to that number. (Cannot
        ## depend on local variables or searchList variables.)
        #indent ++ ## Increment indentation level.
        #indent -- ## Decrement indentation level.
        #indent push ## Save current indentation level. I would allow
        ## another argument afterward to set the new level
        ## immediately.
        #indent pop ## Restore pushed indentation level.
        $indent__ ## Print indentation. If we can arrange for a filter
        ## to have access to this, it could handle the
        ## continuation lines of multiline placeholder values.

        If we do build #indent in, I think it should obey the scoping rules
        of local variables. That is, any changes to the indentation status
        inside a method affect only that method.

        --
        -Mike (Iron) Orr, iron@... (if mail problems: mso@...)
        http://iron.cx/ English * Esperanto * Russkiy * Deutsch * Espan~ol

        _______________________________________________________________

        Don't miss the 2002 Sprint PCS Application Developer's Conference
        August 25-28 in Las Vegas - http://devcon.sprintpcs.com/adp/index.cfm?source=osdntextlink

        _______________________________________________
        Cheetahtemplate-discuss mailing list
        Cheetahtemplate-discuss@...
        https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
      • Mike Orr
        ... Since $indent__ is not normally used by the template maintainer directly, I d call it $_cheetahIndent , to avoid monopolizing a common word maintainers
        Message 3 of 9 , Jun 11, 2002
        • 0 Attachment
          On Tue, Jun 11, 2002 at 09:03:30AM -0700, Mike Orr wrote:
          > $indent__ ## Print indentation. If we can arrange for a filter

          Since $indent__ is not normally used by the template maintainer
          directly, I'd call it $_cheetahIndent , to avoid monopolizing a
          common word maintainers might want to use for another purpose.

          --
          -Mike (Iron) Orr, iron@... (if mail problems: mso@...)
          http://iron.cx/ English * Esperanto * Russkiy * Deutsch * Espan~ol

          _______________________________________________________________

          Don't miss the 2002 Sprint PCS Application Developer's Conference
          August 25-28 in Las Vegas - http://devcon.sprintpcs.com/adp/index.cfm?source=osdntextlink

          _______________________________________________
          Cheetahtemplate-discuss mailing list
          Cheetahtemplate-discuss@...
          https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
        • robert_kuzelj@yahoo.com
          hi mike, ... doesnt that work only for placeholders? but we are looking for linewise processing? ... i had someproblem to figure how to pass all the
          Message 4 of 9 , Jun 12, 2002
          • 0 Attachment
            hi mike,

            > By instantiating your own filter objects, or by calling
            > $currentFilter -aka- self._currentFilter()
            <hmm> doesnt that work only for placeholders? but we
            are looking for linewise processing?

            > BTW, in your script, you don't need to set 'filtersLib' because
            > that's already the default. You only need to set it if you want to
            > use your own custom filter AND you want to specify it by name rather
            > than passing in a class.
            i had someproblem to figure how to pass all the arguments to the
            basetemplate class. so i settled for this one (this might be
            due some holes in my python knowledge).

            > ***
            > Your implementation is quite intriguing and well done, especially
            > how you have an 'if not match' to place $indent in front of all
            > lines, even those that don't have an #indent directive. My comments:
            i thought it might be a bit slow. i guess the regex could be improved
            for speed.

            > ** With some refactoring, one *may* be able to put it into Cheetah.Tools
            > under the name IndentTemplate.py, and then templates could #extends it.
            this is beyond my knowledge of cheetah. i have only recently began
            (that means some two weeks ago) to use cheetah full scale.
            so cant comment on this.

            > But I think we'd have to put the preprocessor call somewhere else
            > rather than __init__, since I think that unless it's a precompiled
            template,
            > __init__ would already be executing/would have finished executing by the
            > time the #extends is discovered. Perhaps Cheetah could have a
            > .preProcess() hook that by default did nothing, but in your case it
            > would modify the source string before the Parser/Compiler saw it.
            > But then we'd want to make it also handle a pipeline of
            > preprocessors too...
            the first sounds good the second even better. the performance-hit
            should be marginal for non-preprocessing templates.

            >
            > ** I wonder if #indent has too many argument options.
            definitly no! ;-)
            well this is what i need at the moment - but i am sure that
            it might be possible to streamline it it bit. the implementation
            i did (which at the beginning borrowed haevily from tavis' impl)
            was just a fast shot that does exactly what i want it to do
            (even so i havent implemented chars= correctly which doesnt bother
            me cause i dont use it at the moment).

            > #indent on ## While the indenter is on, strip leading whitespace
            > ## from source lines, and prepend '$indent__' to every
            > ## line. (This will indent source lines but not
            > ## continuation lines of multi-line placeholders.)
            yep! this is not necessary for myself, cause i dont use multiline
            placeholders. but this is more of a personal style and therefore it
            should be corrected. but this will be a little bit hard cause the processor
            will have to make lookups for the next line(s).
            i'll work on it as soon as i'll find some time (but this will be earliest
            at the end of next week).

            > #indent off ## Restore default behavior.
            > #indent = EXPR ## Set indentation level to that number. (Cannot
            > ## depend on local variables or searchList variables.)
            it could do it very easily i guess(despite the fact that the implementation
            doesnt it at the moment).

            > #indent ++ ## Increment indentation level.
            > #indent -- ## Decrement indentation level.
            > #indent push ## Save current indentation level. I would allow
            > ## another argument afterward to set the new level
            > ## immediately.
            > #indent pop ## Restore pushed indentation level.
            > $indent__ ## Print indentation. If we can arrange for a filter
            > ## to have access to this, it could handle the
            > ## continuation lines of multiline placeholder values.
            once again i am a flat on this one. just one suggestion: the filters-section
            in the docs is a bit short. i would be very good for understanding (at least
            for mine) to extend it, maybe with some concrete filter implementation.

            > If we do build #indent in, I think it should obey the scoping rules
            > of local variables. That is, any changes to the indentation status
            > inside a method affect only that method.
            this i guess won't work, since different methods could work on different
            parts of the same concept. e.g. if one is building sources for a class
            one method might build the class-definition within that method a method
            for building method-definitions is called and within that method the
            statement-definition method is called. what on usually wourld want is that
            the indention level is accumulativ. so methods lower within the call chain
            indent just one more level therefore they have to know the actual
            indention level. ergo indention level is global.

            ciao robertj

            ------------------------------------------------------------
            Robert Kuzelj
            Gaissacherstrasse 7 email: robert_kuzelj@...
            81371 Muenchen tel: 0177/5302230

            the trinity of desirables of (software) architecture:
            Firmitas, Utilitas, Venustas (marcus vitruvius 20 BC)
            strength, utility, beauty



            _______________________________________________________________

            Sponsored by:
            ThinkGeek at http://www.ThinkGeek.com/
            _______________________________________________
            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.