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

Build Nunjucks AST instead of passing to HTMLAsset #1

Closed
devmattrick opened this issue Dec 27, 2017 · 4 comments · Fixed by #11
Closed

Build Nunjucks AST instead of passing to HTMLAsset #1

devmattrick opened this issue Dec 27, 2017 · 4 comments · Fixed by #11

Comments

@devmattrick
Copy link
Collaborator

devmattrick commented Dec 27, 2017

The current functionality is to simple compile the Nunjucks template and then pass it to the HTMLAsset where it is turned into an AST using JSDOM. It may be beneficial performance-wise to use Nunjucks to generate an AST and resolve dependencies from there.

Ideally, the Nunjucks compiler should be used so there are no compatibility issues.

@Seminioni
Copy link

When will you start implementing this issue?

@devmattrick
Copy link
Collaborator Author

@Seminioni I'm not too sure. I have a bit of work to do before this and I'm not too sure if Nunjucks builds a proper AST at all, so I don't know how long this will take.

@chocolateboy
Copy link
Owner

chocolateboy commented Sep 21, 2018

Dependencies can't be determined statically from the AST. Dependencies are expressions (i.e. nonterminals) in nunjucks e.g. the following is valid:

{% set filename = banner.random() %}
{% include filename %}

Dependencies can also be loaded conditionally e.g.:

{% if foo > bar %}
    {% include "footer.html" %}
{% endif %}

Even dependencies that are represented as string literals can't be resolved statically, in general, since the interpretation of the string depends on the loader (i.e. they're identifiers rather than locators) e.g. foo.html could resolve to src/html/foo.html in the filesystem loader or to http://example.com/foo.html in a web loader.

@devmattrick
Copy link
Collaborator Author

Thanks for the insight, @chocolateboy. Turns out Nunjucks is a much more complicated engine that I expected. I'm having trouble finding time to maintain this project, but anyone is welcome to submit PRs if they are able to fix any of these issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants