Rocket example.

This commit is contained in:
Bodil Stokke 2018-11-14 19:00:29 +00:00
parent cc8e7219a2
commit ca77a12599
3 changed files with 52 additions and 1 deletions

View File

@ -2,5 +2,6 @@
members = [
"typed-html",
"macros",
"wasm"
"wasm",
"rocket"
]

9
rocket/Cargo.toml Normal file
View File

@ -0,0 +1,9 @@
[package]
name = "typed-html-rocket-test"
version = "0.1.0"
authors = ["Bodil Stokke <bodil@bodil.org>"]
[dependencies]
typed-html-macros = { path = "../macros" }
typed-html = { path = "../typed-html" }
rocket = "0.4.0-rc.1"

41
rocket/src/main.rs Normal file
View File

@ -0,0 +1,41 @@
#![feature(proc_macro_hygiene, decl_macro, try_from)]
extern crate rocket;
extern crate typed_html;
extern crate typed_html_macros;
use rocket::http::ContentType;
use rocket::response::Content;
use rocket::{get, routes};
use typed_html::text;
use typed_html::types::LinkType;
use typed_html_macros::html;
#[get("/")]
fn index() -> Content<String> {
Content(ContentType::HTML, html!(
<html>
<head>
<title>"Hello Kitty!"</title>
<link rel=LinkType::StyleSheet href="lol.css"/>
</head>
<body>
<h1 data-lol="omg">"Hello Kitty!"</h1>
<p class="official-position-of-sanrio-ltd">
"She is not a "<em><a href="https://en.wikipedia.org/wiki/Cat">"cat"</a></em>". She is a "<em>"human girl"</em>"."
</p>
<p class=["urgent", "question"]>"But how does she eat?"</p>
{
(1..4).map(|i| {
html!(<p>{ text!("{}. Ceci n'est pas une chatte.", i) }</p>)
})
}
<p>"<img src=\"javascript:alert('pwned lol')\">"</p>
</body>
</html>
).to_string())
}
fn main() {
rocket::ignite().mount("/", routes![index]).launch();
}