lambda-fairy / maud

:pencil: Compile-time HTML templates for Rust
https://maud.lambda.xyz
Apache License 2.0
2.09k stars 137 forks source link

Add ability to read html from file #345

Closed alexkazik closed 2 years ago

alexkazik commented 2 years ago

This allows for using external html, when it's a big chunk it's better to read when not part of the rust file.

html_file!("templates/base.maud");

It will be searched relative to the project root.

I've tested this only on top of https://github.com/lambda-fairy/maud/pull/322 and rocket 0.5 support, not on actual main but it should be of no difference.

alexkazik commented 2 years ago

include reads a file and places it in the code so it will be compiled as rust code.

html_file reads a maud template and returns a Html with the template.

And you could use include to do the same but would have to include html! in it, this looks as if it's made for it.

I've done this because it's similar to Haskell's Shakespeare, and they also have macros for in-line and in file.

alexkazik commented 2 years ago

This PR has a little bug anyway.

But it would be a good idea to add an include! example to the website.