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(whiskers): add read_file function #217

Merged
merged 10 commits into from
May 27, 2024
Merged

feat(whiskers): add read_file function #217

merged 10 commits into from
May 27, 2024

Conversation

uncenter
Copy link
Member

@uncenter uncenter commented May 13, 2024

Adds a read_file function for reading the raw contents of files into templates. Workaround for usecases which would usually involve the include builtin but we cannot use it as a) it requires static paths (e.g. you can do {% include "abc.tera" %} but not {% include flavor.identifier ~ ".tera" %}) and b) it preloads all template paths provided by the glob which doesn't allow for the various encodings Whiskers itself supports. EDIT: Also useful for places where including the contents of the LICENSE file is needed.

@nullishamy
Copy link
Contributor

Code seems fine, though I'm thinking it might be more predictable to go from the path of the tera file itself? Thoughts?

@uncenter
Copy link
Member Author

uncenter commented May 19, 2024

Code seems fine, though I'm thinking it might be more predictable to go from the path of the tera file itself? Thoughts?

What do you mean? That is what it does. It uses the parent of the Whiskers template as the root for resolving paths.

@nullishamy
Copy link
Contributor

Usage of cwd in the code would imply to me that it goes from the invocation directory, maybe some docs / rename to make this clearer? Upon closer inspection it seems it does what I'd want it to do, so no qualms about the implementation as such now!

@uncenter
Copy link
Member Author

Yay! Figured out why tests were failing - turns out whitespace control is undocumented for usage in expressions, but you can do it (Keats/tera#919)!

this stops the code panicking on `whiskers -` when read_file is used, and as a side-effect also cleans up the clone dance in read_file_handler.
adds context to errors returned from the `template_directory` function.
without this, we get a platform-specific error message that makes testing harder.
@backwardspy backwardspy merged commit c00881a into catppuccin:main May 27, 2024
6 checks passed
@github-actions github-actions bot mentioned this pull request May 27, 2024
@uncenter uncenter deleted the feat/read_file branch May 27, 2024 15:49
sgoudham pushed a commit that referenced this pull request Jun 3, 2024
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.

3 participants