-
Notifications
You must be signed in to change notification settings - Fork 12
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
Includes to accept expressions not just String literals #17
Comments
This could be useful, but is not a trivial change. Includes are applied
before any code is executed. When a template is loaded, all its includes
are (recursively) loaded before any code executes. Only allowing string
literals makes it trivial, as we do not have to execute any code to
evaluate the includes.
It could still work if you modify the parseInclude method to expect an
expression, and also modify the Include and Include abstract syntax tree
nodes. They need to store an Expression, which is evaluated to a String
when getPath() is called. The getPath() method would need to receive a
context though, which could get very hairy.
…On Mon, Jul 30, 2018, 5:11 PM Impaler ***@***.***> wrote:
Consider the following code that iterates through a huge array of sections
to include a list of generated files.
{{for section in sections}}
<code>{{ include section.get_example_curl}}</code>
<code>{{ include section.post_example_curl}}</code>
{{end}}
There only way to achieve it is to hardcode the path.
<code>{{ include "../target/generated-snippets/section1/get-example/curl-request.md"}}</code>
<code>{{ include "../target/generated-snippets/section1/post-example/curl-request.md"}}/code>
...
<code>{{ include "../target/generated-snippets/sectionX/get-example/curl-request.md"}}</code>
<code>{{ include "../target/generated-snippets/sectionX/post-example/curl-request.md"}}/code>
I haven't properly understood the code so far, but it looks like the
Parser#parseInclude is the place to do it. I raised this issue as an
improvement, as it's not really an issue.
If I come up with a solution I will do a PR if it gets accepted as an
improvement.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#17>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAfYBOsX_CyDdhHlQtKntTtoDD6m5aFrks5uLyICgaJpZM4VmmHR>
.
|
It's not trivial indeed and thanks for the pointers. It's a rare use-case, so have to weight that in. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Consider the following code that iterates through a huge array of sections to include a list of generated files.
There only way to achieve it is to hardcode the path.
I haven't properly understood the code so far, but it looks like the
Parser#parseInclude
is the place to do it. I raised this issue as an improvement, as it's not really an issue.If I come up with a solution I will do a PR if it gets accepted as an improvement.
The text was updated successfully, but these errors were encountered: