add support for ructe templates #28
prabirshrestha
started this conversation in
Ideas
Replies: 2 comments 3 replies
-
This seems like it would be a great addition, but given how many other framework-essential handlers I need to write (#17) and given that there are three template languages currently, I'd be more inclined to advise and review if someone else wants to write it, and would happily add it to the documentation. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Here is a sample ructe working example in case others are interested. include!(concat!(env!("OUT_DIR"), "/templates.rs"));
fn render<Call>(call: Call) -> String
where
Call: FnOnce(&mut dyn Write) -> std::io::Result<()>,
{
let mut buf = Vec::new();
call(&mut buf).unwrap();
String::from_utf8(buf).unwrap()
}
async fn not_found(conn: Conn) -> Conn {
let contents = render(|o| templates::notfound_html(o, conn.path()));
conn.with_body(contents)
.with_header(("content-type", "text/html"))
.with_status(404)
} notfound.rs.html @(path: &str)
<h1>@path Not Found</h1> build.rs use ructe::{Result, Ructe};
fn main() -> Result<()> {
let mut ructe = Ructe::from_env()?;
let mut statics = ructe.statics()?;
statics.add_files("static")?;
ructe.compile_templates("templates")?;
Ok(())
} A better wrapper something like |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Add ructe templating support. It catches most of the errors at compile time and also has an optional SASS compilation support to convert it to CSS.
//cc @kaj
Beta Was this translation helpful? Give feedback.
All reactions