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

feat: New eval function to evaluate a template #485

Merged
merged 1 commit into from
Jan 24, 2023

Conversation

rhansen
Copy link
Collaborator

@rhansen rhansen commented Jan 14, 2023

This makes it possible to:

  • modularize a template by using an embedded template (defined with Go's built-in define action) as a function whose return value is the expansion of the template
  • post-process the expansion of a template (e.g., pipe it to Sprig's indent function)

For additional context, see golang/go#54748. Sprig is unlikely to add an equivalent to this function any time soon: the function must be a closure around the template, meaning either Sprig or Go would have to change its API.

@buchdag
Copy link
Member

buchdag commented Jan 17, 2023

Is the idea behind this PR to modularise the nginx-proxy template instead of using more and more template ?

@rhansen
Copy link
Collaborator Author

rhansen commented Jan 17, 2023

The idea is to make it easier to modularize. Technically it's currently possible to use templates as functions, but the return value has to be stored in the template's dot dict instead of the more natural/readable approach of writing it out. (See nginx-proxy/nginx-proxy#1938 for an example.)

This makes it possible to:
  * modularize a template by using an embedded template (defined with
    Go's built-in `define` action) as a function whose return value is
    the expansion of the template
  * post-process the expansion of a template (e.g., pipe it to
    Sprig's `indent` function)

For additional context, see
<golang/go#54748>.  Sprig is unlikely to add
an equivalent to this function any time soon: the function must be a
closure around the template, meaning either Sprig or Go would have to
change its API.
@rhansen rhansen merged commit c7b991e into nginx-proxy:main Jan 24, 2023
@rhansen rhansen deleted the eval branch January 24, 2023 01:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants