aboutsummaryrefslogtreecommitdiffstats
path: root/askama_rocket
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--askama_rocket/Cargo.toml17
-rw-r--r--askama_rocket/src/lib.rs16
-rw-r--r--askama_rocket/templates/hello.html1
-rw-r--r--askama_rocket/tests/basic.rs (renamed from testing/tests/rocket.rs)1
4 files changed, 34 insertions, 1 deletions
diff --git a/askama_rocket/Cargo.toml b/askama_rocket/Cargo.toml
new file mode 100644
index 0000000..e557a38
--- /dev/null
+++ b/askama_rocket/Cargo.toml
@@ -0,0 +1,17 @@
+[package]
+name = "askama_rocket"
+version = "0.9.0"
+authors = ["Dirkjan Ochtman <dirkjan@ochtman.nl>"]
+description = "Rocket integration for Askama templates"
+documentation = "https://docs.rs/askama"
+keywords = ["markup", "template", "jinja2", "html"]
+categories = ["template-engine"]
+homepage = "https://github.com/djc/askama"
+repository = "https://github.com/djc/askama"
+license = "MIT OR Apache-2.0"
+workspace = ".."
+edition = "2018"
+
+[dependencies]
+askama = { version = "0.9.0", path = "../askama", features = ["with-rocket", "mime", "mime_guess"] }
+rocket = { version = "0.4", default-features = false }
diff --git a/askama_rocket/src/lib.rs b/askama_rocket/src/lib.rs
new file mode 100644
index 0000000..6db3b7b
--- /dev/null
+++ b/askama_rocket/src/lib.rs
@@ -0,0 +1,16 @@
+use std::io::Cursor;
+
+pub use askama::*;
+use rocket::http::{ContentType, Status};
+pub use rocket::request::Request;
+use rocket::response::Response;
+pub use rocket::response::{Responder, Result};
+
+pub fn respond<T: Template>(t: &T, ext: &str) -> Result<'static> {
+ let rsp = t.render().map_err(|_| Status::InternalServerError)?;
+ let ctype = ContentType::from_extension(ext).ok_or(Status::InternalServerError)?;
+ Response::build()
+ .header(ctype)
+ .sized_body(Cursor::new(rsp))
+ .ok()
+}
diff --git a/askama_rocket/templates/hello.html b/askama_rocket/templates/hello.html
new file mode 100644
index 0000000..8149be7
--- /dev/null
+++ b/askama_rocket/templates/hello.html
@@ -0,0 +1 @@
+Hello, {{ name }}!
diff --git a/testing/tests/rocket.rs b/askama_rocket/tests/basic.rs
index 3dbc357..0671c4c 100644
--- a/testing/tests/rocket.rs
+++ b/askama_rocket/tests/basic.rs
@@ -1,4 +1,3 @@
-#![cfg(feature = "with-rocket")]
#![feature(proc_macro_hygiene, decl_macro)]
#[macro_use]