Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support content selection using meta tags #99

Closed
traut opened this issue Feb 17, 2024 · 1 comment · Fixed by #251
Closed

Support content selection using meta tags #99

traut opened this issue Feb 17, 2024 · 1 comment · Fixed by #251
Labels
cli enhancement New feature or request
Milestone

Comments

@traut
Copy link
Member

traut commented Feb 17, 2024

Background

In some cases, the structure of a produced document must slightly differ based on requirements. To avoid creating multiple templates for slightly different use cases, it should be possible to configure the rendering of the same template during execution.

Fabric already supports a version of this with no results condition and it should also be possible to mutate the template structure by runtime configuration.

Design

A straightforward way of achieving the reconfigurability of the template structure is to support tag filtering of the target blocks.

  • the document / section / content blocks already support embedded meta blocks with tags attributes (PR TBD)
  • Fabric CLI render subcommand should accept one or more tag values with --with-meta-tag argument
  • during the evaluation, only the document/section/content blocks that contain all provided tags in meta.tags are added to the output.

Note

The nesting nature of the templates requires the leaves-first filtering, meaning that if the parent block does not match the tag filter, but any of its descendants do match, the parent block is included in the output with all its descendants that match.

It also means all its descendants are included by default if the parent block matches the filter.

  • the document to be rendered (set as target in the render command) is also evaluated:
    • if only document block matches the provided tags but none of its descendants do, it is fully rendered
    • if document block does not match the provided tags but some of its descendants do, the document is rendered only with the descendants included in the output

Note

To simplify the logic that figures out what to render, keeping in mind the depends_on dependencies, the filtering can happen post rendering, meaning the whole tree is evaluated but only the matching blocks are included in the output.

For example, with the template

document "test_doc" {

  meta {
    name = "Test Template"
    tags = ["foo", "bar"]
  }

  data inline "x" {
    items = ["aaa", "bbb", "ccc"]
  }

  content text {
    meta {
      tags = ["bar", "qux"]
    }
    query = ".data.inline.x.items | length"
    text = "There are {{ .query_result }} items"
  }

  content text {
    meta {
      tags = ["qux", ]
    }
    text = "Other static text"
  }
}

The results will differ depending on the CLI command:

  • if foo tag is set:
    $ fabric render document.test_doc --with-meta-tag foo
    There are 3 items
    
    Other static text
  • if bar tag is set:
    $ fabric render document.test_doc --with-meta-tag bar
    There are 3 items
    
    Other static text
  • if qux tag is set:
    $ fabric render document.test_doc --with-meta-tag qux
    There are 3 items
    
    Other static text
@traut traut added the enhancement New feature or request label Feb 17, 2024
@traut traut added this to the v0.4 milestone Feb 17, 2024
@traut traut changed the title Support selection of blocks using meta tags Support content selection using meta tags Feb 18, 2024
@traut traut added the cli label Mar 3, 2024
@traut traut mentioned this issue Mar 31, 2024
@traut traut modified the milestones: v0.4, v0.5 May 12, 2024
@traut
Copy link
Member Author

traut commented May 12, 2024

moved to milestone 0.5 to wait for #159 as it is an enabler for this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant