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 variable requirements in referenced blocks #29

Open
traut opened this issue Jan 10, 2024 · 0 comments
Open

Support variable requirements in referenced blocks #29

traut opened this issue Jan 10, 2024 · 0 comments
Labels
enhancement New feature or request fcl
Milestone

Comments

@traut
Copy link
Member

traut commented Jan 10, 2024

Background

The reference-able content blocks, defined on the root level of the codebase, need to access specific data points from the context. The content block might not know the exact keys available in the context, making the logic inside the block fragile and error-prone. This makes block reuse difficult.

The blocks that allow vars blocks (content, document, section blocks) and that can be referenced, should be able to declare the requirements: a list of variables a block expects to find in the context during execution.

Design

We introduce a new arrtibute to the content, document and section blocks:

required_vars -- (optional) a list of strings

required_vars defines the names of the variables that the block expectes to find in the context under .vars namespace.

For example:

content text "hello" {
  text = "Hello, {{ .vars.name }}"
  required_vars = ["name"]
}

content text "greeting" {
  text = "Greetings, {{ .vars.other_name }}"
  required_vars = ["other_name"]
}

document "bar" {
  vars {
    name = "Bruce"
  }

  content ref {
    base = content.text.hello
  }

  content ref {
    vars {
      other_name = query_jq(".vars.name")
    }
    base = content.text.greetings
  }
}

renders into

Hello, Bruce
Greetings, Bruce

Note: Required variables should be asserted during evaluation of the block, not during ref block resolution (since the data is not available yet)

References

@traut traut added the enhancement New feature or request label Jan 10, 2024
@traut traut added this to the v0.1 milestone Jan 10, 2024
@traut traut modified the milestones: v0.1, v0.4 Feb 23, 2024
@traut traut changed the title Support optional query input for content blocks Support optional block data for referenced content blocks Apr 9, 2024
@traut traut added the draft label Apr 24, 2024
@traut traut removed this from the v0.4 milestone Apr 26, 2024
@traut traut changed the title Support optional block data for referenced content blocks Support variable requirements in content blocks May 21, 2024
@traut traut changed the title Support variable requirements in content blocks Support variable requirements in referenced blocks May 21, 2024
@traut traut added this to the v0.5 milestone May 21, 2024
@traut traut added fcl and removed draft labels May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fcl
Projects
None yet
Development

No branches or pull requests

1 participant