Skip to content

Commit

Permalink
Remove dependency on ring
Browse files Browse the repository at this point in the history
  • Loading branch information
w4 committed Feb 16, 2019
1 parent caa8c35 commit c3b886c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 64 deletions.
73 changes: 23 additions & 50 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ edition = "2018"

[dependencies]
linked-hash-map = "0.5"
rocket = "0.4"
askama = { git = "https://github.com/djc/askama", rev = "fc5addc4", features = ["with-rocket"] }
askama_escape = { git = "https://github.com/djc/askama", rev = "fc5addc4" }
rocket = { version = "0.4", default-features = false }
askama = "0.7"
lazy_static = "1.2"
rand = "0.6"
rand = { version = "0.6", features = ["nightly"] }
gpw = "0.1"
syntect = "3.0"
serde_derive = { version = "1.0" }
serde_derive = "1.0"

[profile.release]
lto = true
Expand Down
19 changes: 10 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ extern crate lazy_static;
extern crate rocket;

extern crate askama;
extern crate askama_escape;

mod highlight;
mod io;
Expand All @@ -18,8 +17,7 @@ use highlight::highlight;
use io::{generate_id, get_paste, store_paste};
use params::{HostHeader, IsPlaintextRequest};

use askama::Template;
use askama_escape::{Html, MarkupDisplay};
use askama::{MarkupDisplay, Template};

use rocket::http::{ContentType, Status};
use rocket::request::Form;
Expand All @@ -35,11 +33,14 @@ use std::io::Read;
#[derive(Template)]
#[template(path = "index.html")]
struct Index {}
struct Index;

#[get("/")]
fn index() -> Index {
Index {}
fn index() -> Result<rocket::response::content::Html<String>, Status> {
Index
.render()
.map(|h| rocket::response::content::Html(h))
.map_err(|_| Status::InternalServerError)
}

///
Expand Down Expand Up @@ -79,7 +80,7 @@ fn submit_raw(input: Data, host: HostHeader) -> std::io::Result<String> {
#[derive(Template)]
#[template(path = "paste.html")]
struct ShowPaste {
content: MarkupDisplay<Html, String>,
content: MarkupDisplay<String>,
}

#[get("/<key>")]
Expand All @@ -96,9 +97,9 @@ fn show_paste(key: String, plaintext: IsPlaintextRequest) -> Result<Content<Stri
Ok(Content(ContentType::Plain, entry))
} else {
let content = match ext {
None => MarkupDisplay::new_unsafe(entry, Html),
None => MarkupDisplay::Unsafe(entry),
Some(extension) => highlight(&entry, extension)
.map(|h| MarkupDisplay::new_safe(h, Html))
.map(|h| MarkupDisplay::Safe(h))
.ok_or_else(|| Status::NotFound)?,
};

Expand Down

0 comments on commit c3b886c

Please sign in to comment.