Re: Proposed: #indent directive
Claude Brisson <[email protected]>
| Newsgroups | gmane.comp.jakarta.velocity.devel |
|---|---|
| Message-ID | <[email protected]> |
The use case you give is also not clear to me. What does `writeNodeAsJson()` do on arrays or maps if you still have to call `walktree()` on children? Where is the final ']' or '}' written? Usually, I do solve such problems of displaying a tree using an extra `$indentation` argument which is just passed to the recursive macro with additional spaces and it's sufficient (and frankly, this is most easily done in Java rather in VTL where it's not exactly pertinent...). On 07/04/2025 00:58, Nathan Bubna wrote: > A PR to look over would be good. > > On Sun, Apr 6, 2025 at 9:41 AM Bear Giles <[email protected]> wrote: > >> I've been working on a contribution to maven-dependency-plugin and spent a >> fair amount of time trying to figure out how to cleanly implement proper >> indentation when converting the dependency tree to json, yaml, etc. >> >> After a bit of pain, okay a lot of pain, I have finally implemented a new >> Directive - 'indent' - which extends Block and prepends a 'padding' value >> on render(). This works since render() is also called recursively. >> >> (I know there's a TreeContext but I have no idea how to use it, whether it >> can be used within the existing plugin, or even if it would help solve this >> problem.) >> >> An example of how it is used is: >> >> #macro (writeNodeAsJson $node) >> // do the json magic >> #end >> >> #macro (walktree $node) >> #indent >> #writeNodeAsJson($node) >> #foreach ($child in $node.children) >> #walktree ($node) >> #end >> #end >> #end >> >> (I don't have that code on this system so there may be a slight error in >> it.) >> >> At the moment the directive doesn't take any parameter but I do plan to add >> an optional one, ideally either a string literal or a reference, but I >> haven't coded it yet. In theory it could even be a reference to a different >> macro, e.g., so you could have 'I", "II",... then 'a','b'..., then >> '1','2'... since the macro could be provided the current indentation depth >> but I'll leave that for another day. >> >> I think I have JIRA access and if so I'll create an issue and submit a PR. >> >> Bear Giles >>