Skip to content

Prettier format template files#3084

Open
drgrice1 wants to merge 3 commits into
openwebwork:developfrom
drgrice1:prettier-format-template-files
Open

Prettier format template files#3084
drgrice1 wants to merge 3 commits into
openwebwork:developfrom
drgrice1:prettier-format-template-files

Conversation

@drgrice1

Copy link
Copy Markdown
Member

The @openwebwork/prettier-plugin-mojolicious-html-template package is a prettier plugin that formats HTML with prettier and uses perltidy to format Perl content inside the Mojolicious template regions.

The @openwebwork/prettier-plugin-mojolicious-html-template project repository is housed at https://github.com/openwebwork/prettier-plugin-mojolicious-html-template. I am giving ownership of the repository to webwork, because the project was developed with the usage of Claude code, and that usage was funded by the webwork project.

So this is my first Claude powered pull request.

Note that the first commit adds the framework for using prettier with the plugin on template files, the second applies prettier with the plugin to all template files, and the third does some manual clean up. The manual clean up is mostly of strings in the help files because the new formatting ends up indenting them another level and makes the strings exceed the 120 character limit.

I am targeting this to develop. There is certainly no urgency for adding this to the 2.21 release as it is a development only thing.

Note that the bin/dev_scripts/pod-templates/main-index.mt file is not formatted at this point. The .mt extension is not handled by the plugin, and is in fact not even a valid extension for a Mojolicious template file. That extension was introduced by @pstaabp at some point, and we just kind of went with it. Really any Mojolicious template file should have the extension .[output-format].ep or .[output-format].epl where [output-format] is the type of file generated when the template is rendered. Note that a file rendered by the Mojo::Template package directly or rendered by the Mojolicious::Plugin::EPLRenderer.pm package (which is just a thin wrapper around the Mojo::Template package) should use the .epl extension, and any rendered via the Mojolicious::Plugion::EPRenderer.pm package should use the .ep extension (this is how anything rendered by a Mojolicious:Controller is rendered). So the bin/dev_scripts/pod-templates/main-index.mt should be ``bin/dev_scripts/pod-templates/main-index.html.epl`.

Also, the courses.dist/modelCourse/templates/achievements/notifications/default.html.ep is incorrectly named. It should be courses.dist/modelCourse/templates/achievements/notifications/default.txt.ep (or really courses.dist/modelCourse/templates/achievements/notifications/default.txt.epl since it is rendered via Mojo::Template directly). This file certainly should not be formatted since it is not HTML, and the plugin only handles HTML template formatting. Text can't be formatted in any case (other than perhaps line wrapping). Due to this

Fixing those file naming issues is left for later.

drgrice1 added 3 commits July 23, 2026 21:09
This uses the `@openwebwork/prettier-plugin-mojolicious-html-template`
package to do so. That package is a `prettier` plugin that formats HTML
with `prettier` and uses `perltidy` to format Perl content inside the
Mojolicious template regions.

The `@openwebwork/prettier-plugin-mojolicious-html-template` project
repository is housed at https://github.com/openwebwork/prettier-plugin-mojolicious-html-template.
I am giving ownership of the repository to webwork, because the project
was developed with the usage of Claude code, and that usage was funded
by the webwork project.
@drgrice1

Copy link
Copy Markdown
Member Author

I forgot to mention the most important thing for developers. To format the template files you just do what you did before to format the JavaScript and css files. Execute npm run prettier-format from the htdocs directory. So now anytime you change a JavaScript, css (or scss), or Mojolicious template file do that to ensure they are formatted correctly for the workflow.

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.

1 participant