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",
"macros",
"examples/stdweb",
"examples/rocket",
"examples/iron",
"examples/dodrio/counter",
"examples/dodrio/todomvc",
"ui",

View File

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

View File

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