Replace Rocket example with Iron example, which builds on stable rustc.

This commit is contained in:
Bodil Stokke 2019-04-08 16:47:00 +01:00
parent ccb00646ac
commit 66320b0bdb
3 changed files with 15 additions and 22 deletions

View File

@ -3,7 +3,7 @@ members = [
"typed-html", "typed-html",
"macros", "macros",
"examples/stdweb", "examples/stdweb",
"examples/rocket", "examples/iron",
"examples/dodrio/counter", "examples/dodrio/counter",
"examples/dodrio/todomvc", "examples/dodrio/todomvc",
"ui", "ui",

View File

@ -1,5 +1,5 @@
[package] [package]
name = "typed-html-rocket-test" name = "typed-html-iron-test"
version = "0.1.0" version = "0.1.0"
edition = "2018" edition = "2018"
authors = ["Bodil Stokke <bodil@bodil.org>"] authors = ["Bodil Stokke <bodil@bodil.org>"]
@ -7,4 +7,4 @@ authors = ["Bodil Stokke <bodil@bodil.org>"]
[dependencies] [dependencies]
typed-html-macros = { path = "../../macros" } typed-html-macros = { path = "../../macros" }
typed-html = { path = "../../typed-html" } typed-html = { path = "../../typed-html" }
rocket = "0.4.0-rc.1" iron = "0.6.0"

View File

@ -1,27 +1,19 @@
#![recursion_limit = "256"] #![recursion_limit = "256"]
#![feature(proc_macro_hygiene, decl_macro)]
extern crate rocket; use iron::headers::ContentType;
extern crate typed_html; use iron::modifier::Modifier;
extern crate typed_html_macros; use iron::prelude::*;
use iron::status;
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::elements::FlowContent;
use typed_html::types::LinkType; use typed_html::types::LinkType;
use typed_html::{dom::DOMTree, html, text, OutputType}; use typed_html::{dom::DOMTree, html, text, OutputType};
struct Html(DOMTree<String>); struct Html(DOMTree<String>);
impl<'r> Responder<'r> for Html { impl Modifier<Response> for Html {
fn respond_to(self, _request: &Request) -> Result<'r> { fn modify(self, res: &mut Response) {
Ok(Response::build() res.body = Some(Box::new(self.0.to_string()));
.status(Status::Ok) res.headers.set(ContentType::html());
.header(ContentType::HTML)
.sized_body(Cursor::new(self.0.to_string()))
.finalize())
} }
} }
@ -46,9 +38,8 @@ fn doc<T: OutputType + 'static>(tree: Box<dyn FlowContent<T>>) -> DOMTree<T> {
) )
} }
#[get("/")]
fn index() -> Html { fn index() -> Html {
let a = false; let a = true;
Html(doc(html!( Html(doc(html!(
<div> <div>
<h1 data-lol="omg">"Hello Kitty!"</h1> <h1 data-lol="omg">"Hello Kitty!"</h1>
@ -68,5 +59,7 @@ fn index() -> Html {
} }
fn main() { fn main() {
rocket::ignite().mount("/", routes![index]).launch(); Iron::new(|_: &mut Request| Ok(Response::with((status::Ok, index()))))
.http("localhost:1337")
.unwrap();
} }