From 8e26aec619be32a78ab03ecf41daf209d220b0a2 Mon Sep 17 00:00:00 2001 From: Lev Kokotov Date: Mon, 28 Oct 2024 15:45:28 -0700 Subject: [PATCH] More helpful template errors (#11) --- ROADMAP.md | 5 + rwf/src/http/error.html | 31 +++++ rwf/src/http/response.rs | 16 ++- rwf/src/http/server.rs | 9 +- rwf/src/view/template/error.rs | 121 +++++++++++++++++-- rwf/src/view/template/language/expression.rs | 2 +- rwf/src/view/template/lexer/token.rs | 15 +++ rwf/src/view/template/mod.rs | 33 +++-- 8 files changed, 215 insertions(+), 17 deletions(-) create mode 100644 rwf/src/http/error.html diff --git a/ROADMAP.md b/ROADMAP.md index 34e2ae09..3f2f2879 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -19,6 +19,7 @@ Rwf is brand new, but web development is ancient. Many features are missing or a - [ ] EventStreams - [ ] Integration tests - [ ] Support for multiple WebSocket controllers (`Comms::websocket` assumes only one) +- [ ] Multipart forms ## Dynanic templates @@ -48,6 +49,10 @@ Rwf is brand new, but web development is ancient. Many features are missing or a - [ ] Consider using granian (https://github.com/levkk/rwf/issues/4) +## Migrate from Ruby + +- [ ] Add support for running Rake apps (e.g. Rails) + ## Built-ins - [ ] Feature flags and experiments diff --git a/rwf/src/http/error.html b/rwf/src/http/error.html new file mode 100644 index 00000000..76ca623b --- /dev/null +++ b/rwf/src/http/error.html @@ -0,0 +1,31 @@ + + + + <%= title %> + + + +
+

<%= title %>

+
+
+
<%= message %>
+
+ + diff --git a/rwf/src/http/response.rs b/rwf/src/http/response.rs index f6350901..8fd61440 100644 --- a/rwf/src/http/response.rs +++ b/rwf/src/http/response.rs @@ -1,14 +1,20 @@ //! HTTP response. +use once_cell::sync::Lazy; use serde::Serialize; use std::collections::HashMap; use std::marker::Unpin; use tokio::io::{AsyncWrite, AsyncWriteExt}; use super::{head::Version, Body, Cookie, Cookies, Error, Headers, Request}; -use crate::view::TurboStream; +use crate::view::{Template, TurboStream}; use crate::{config::get_config, controller::Session}; +static ERROR_TEMPLATE: Lazy