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

generator: remove custom context #1886

Merged
merged 12 commits into from
Apr 2, 2024
Merged

generator: remove custom context #1886

merged 12 commits into from
Apr 2, 2024

Conversation

senekor
Copy link
Contributor

@senekor senekor commented Mar 31, 2024

crate_name and fn_names were previously injected into the context for rendering a test template to allow something like the following in a template:

let output = {{ crate_name }}::{{ fn_names[0] }}(input);

This made both the templates and Rust code for the generator more complicated. The benefit is only a few characters less typing when creating the template once. In hindsight, this is not worth it in my opinion.

[no important files changed]

The logic to extract the function names from the lib.rs stub to use it
for exercise generation doesn't really add any value, it just makes
things more complicated. First of all, the Rust code itself.
But also the tera templates, which contain a {{ fn_names[0] }}.

All for saving a few characters of typing when creating a new template.
That's not worth it in my opinion. The templating context should only
contain things that actually change dynamically, namely the test data.
Comment on lines -137 to -139
If every test case needs to do some crunching of the inputs,
you can add utils functions at the top of the tera template.
See [`word-count`'s template][word-count-tmpl] for an example.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a piggy-back, I removed this recommendation because of reasons explained in #1824

Base automatically changed from sync-docs to main April 2, 2024 07:37
@senekor senekor merged commit 37449b6 into main Apr 2, 2024
10 checks passed
@senekor senekor deleted the clean-context branch April 2, 2024 07:54
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.

2 participants