Details

    • Type: Wish Wish
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.0-Release
    • Fix Version/s: 2.x
    • Component/s: Engine
    • Labels:
      None
    • Environment:
      Operating System: other
      Platform: Other

      Description

      I expect that when adding velocity markup to an existing text file
      to not affect the spacing in the output. This includes indented #foreach
      directives and inner indented #if/#set/#macro directives.

      So the rule I proposed was to allow adding velocity markup, one per line,
      and still have the same output - e.g. add an #if statement around
      existing text to conditionally mask it out. Or add an #foreach around
      a table row and be able to repeat the body with dynamic data, etc.

      As sonn as a directive is placed wihtin other text in the same line,
      any whitespace around it should remain untouched.

      If a line is looks like this:
      DirectiveLine ::= LineEnd TabsAndSpaces? Directive TabsAndSpaces? LineEnd
      TabsAndSpaces ::= (#x20 | #x09)+
      LineEnd ::= StartOfStream | ((#x0D #x0A) | #x0D | #x0A) | EndOfStream
      then the first "TabsAndSpaces?" and the closing "TabsAndSpaces? LineEnd"
      should be gobbled. (Note that it supports multiline directives, that is
      why "DirectiveLine" is not simply "Line".) If you whant the first
      "LineEnd" to be gobbled prepend a ## before it (makes the EOL part of
      the previous line!).

      This has been an isse since velocity birth and discussed in many
      user and developer threads. Some users agree with my proposals,
      some say that velocity sould not touch any whitespaces and a
      code formatter should be run after the template rendering.

      The proposal is not 100% BC, but a switch could allow the classic
      style (by default), or to pass all whitespaces.

      A new directive could be created to control the gobbling for
      the enclosed parts within a template.

        Issue Links

          Activity

          Hide
          jrn added a comment -

          At the very least, Velocity shouldn't be moving whitespace onto other lines.
          When I write a line with only whitespace and a Velocity directive, I don't
          expect that whitespace to be moved onto the line below it! I'd prefer to have
          lines with only whitespace, over the current situation...

          Show
          jrn added a comment - At the very least, Velocity shouldn't be moving whitespace onto other lines. When I write a line with only whitespace and a Velocity directive, I don't expect that whitespace to be moved onto the line below it! I'd prefer to have lines with only whitespace, over the current situation...
          Hide
          Will Glass-Husain added a comment -

          FYI. There's an extensive discussion of this in the WIKI. Scheduling for 2.0.

          Be great if someone wanted to take a crack at a patch at some point. The tricky thing of course is that a lot of this behavior is specified with tokens in Parser.jjt. Thus a "configuration switch" is pretty tough.

          Show
          Will Glass-Husain added a comment - FYI. There's an extensive discussion of this in the WIKI. Scheduling for 2.0. Be great if someone wanted to take a crack at a patch at some point. The tricky thing of course is that a lot of this behavior is specified with tokens in Parser.jjt. Thus a "configuration switch" is pretty tough.
          Hide
          Nathan Bubna added a comment -

          Yes, a configuration switch is pretty much impossible if you treat any whitespace outside VTL constructs as special. this is one of my arguments for no-gobbling. see the last section of http://wiki.apache.org/jakarta-velocity/VelocityWhitespaceGobbleNone for more on it. if the parser does gobbling, then our ability to configure gobbling rules becomes severly reduced. perhaps i'll have to dig up some time to up the ante and produce a no-parser-gobbling patch for a post-1.5 release.

          Show
          Nathan Bubna added a comment - Yes, a configuration switch is pretty much impossible if you treat any whitespace outside VTL constructs as special. this is one of my arguments for no-gobbling. see the last section of http://wiki.apache.org/jakarta-velocity/VelocityWhitespaceGobbleNone for more on it. if the parser does gobbling, then our ability to configure gobbling rules becomes severly reduced. perhaps i'll have to dig up some time to up the ante and produce a no-parser-gobbling patch for a post-1.5 release.
          Hide
          Will Glass-Husain added a comment -

          Thanks for suggestion this. There's been a bunch of debate on this topic. See the Wiki for more info - feel free to contribute. I'm going to mark this invalid since it's posted elsewhere.

          Show
          Will Glass-Husain added a comment - Thanks for suggestion this. There's been a bunch of debate on this topic. See the Wiki for more info - feel free to contribute. I'm going to mark this invalid since it's posted elsewhere.
          Hide
          Henning Schmiedehausen added a comment -

          change reporter as requested by christoph reck.

          Show
          Henning Schmiedehausen added a comment - change reporter as requested by christoph reck.
          Hide
          Byron Foster added a comment - - edited

          It seem straight forward to alter the parser so that no white space is consumed. Then, with a property switch, the AST tree could be walked and altered so that white space is aggressively removed post-parse according to the rules provided in the issue discription.

          Show
          Byron Foster added a comment - - edited It seem straight forward to alter the parser so that no white space is consumed. Then, with a property switch, the AST tree could be walked and altered so that white space is aggressively removed post-parse according to the rules provided in the issue discription.
          Hide
          Claude Brisson added a comment - - edited

          I submitted a structured whitespace globber implementation that uses an early filtering of unwanted whitespaces while resources are loaded - it's an alpha version, and I don't think that it can replace a proper implementation included in the parser, but I made some use of it so I share it on the wiki: http://wiki.apache.org/velocity/StructuredGlobbingResourceLoader

          Show
          Claude Brisson added a comment - - edited I submitted a structured whitespace globber implementation that uses an early filtering of unwanted whitespaces while resources are loaded - it's an alpha version, and I don't think that it can replace a proper implementation included in the parser, but I made some use of it so I share it on the wiki: http://wiki.apache.org/velocity/StructuredGlobbingResourceLoader

            People

            • Assignee:
              Unassigned
              Reporter:
              Christoph Reck
            • Votes:
              4 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:

                Development