#![recursion_limit = "256"] #![feature(proc_macro_hygiene, decl_macro)] extern crate rocket; extern crate typed_html; extern crate typed_html_macros; use rocket::http::{ContentType, Status}; use rocket::response::{Responder, Result}; use rocket::{get, routes, Request, Response}; use std::io::Cursor; use typed_html::elements::FlowContent; use typed_html::types::LinkType; use typed_html::{dom::DOMTree, html, text, OutputType}; struct Html(DOMTree); impl<'r> Responder<'r> for Html { fn respond_to(self, _request: &Request) -> Result<'r> { Ok(Response::build() .status(Status::Ok) .header(ContentType::HTML) .sized_body(Cursor::new(self.0.to_string())) .finalize()) } } // Function that wraps a DOM node in an HTML document, to demonstrate how you'd // do this sort of templating. // // It's a bit more complicated than you'd hope because you need to take an input // argument of the type that the element that you're inserting it into expects, // which in the case of `` is `FlowContent`, not just `Node`, so you can't // pass it a `DOMTree` or you'll get a type error. fn doc(tree: Box>) -> DOMTree { html!( "Hello Kitty!" { tree } ) } #[get("/")] fn index() -> Html { let a = false; Html(doc(html!(

"Hello Kitty!"

"She is not a ""cat"". She is a ""human girl""."

"But how does she eat?"

{ (1..4).map(|i| { html!(

{ text!("{}. Ceci n'est pas une chatte.", i) }

) }) }

""

: String))) } fn main() { rocket::ignite().mount("/", routes![index]).launch(); }