🏡 index : ~doyle/bin.git

author Jordan Johnson-Doyle <jordan@doyle.la> 2019-02-16 11:48:42.0 +00:00:00
committer Jordan Johnson-Doyle <jordan@doyle.la> 2019-02-16 11:51:14.0 +00:00:00
commit
f675f75b3bcd581e6af369d0a6c27ce8ed967085 [patch]
tree
d9be935fb5c9c058ade15aa26aed125f59c88556
parent
cd3d911ca075d9608051ef5ff0a63dbe12781286
download
f675f75b3bcd581e6af369d0a6c27ce8ed967085.tar.gz

Rename render -> show_paste



Diff

 src/main.rs | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)

diff --git a/src/main.rs b/src/main.rs
index 4da138b..5479ee9 100644
--- a/src/main.rs
+++ a/src/main.rs
@@ -55,7 +55,7 @@
fn submit(input: Form<IndexForm>) -> Redirect {
    let id = generate_id();
    store_paste(id.clone(), input.into_inner().val);
    Redirect::to(uri!(render: id))
    Redirect::to(uri!(show_paste: id))
}

#[put("/", data = "<input>")]
@@ -67,7 +67,7 @@
    store_paste(id.clone(), data);

    match *host {
        Some(host) => Ok(format!("https://{}/{}", host, id)),
        Some(host) => Ok(format!("https://{}{}", host, uri!(show_paste: id))),
        None => Ok(id),
    }
}
@@ -78,12 +78,12 @@

#[derive(Template)]
#[template(path = "paste.html")]
struct Render {
struct ShowPaste {
    content: MarkupDisplay<Html, String>,
}

#[get("/<key>")]
fn render(key: String, plaintext: IsPlaintextRequest) -> Result<Content<String>, Status> {
fn show_paste(key: String, plaintext: IsPlaintextRequest) -> Result<Content<String>, Status> {
    let mut splitter = key.splitn(2, '.');
    let key = splitter.next().ok_or_else(|| Status::NotFound)?;
    let ext = splitter.next();
@@ -95,16 +95,14 @@
    if *plaintext {
        Ok(Content(ContentType::Plain, entry))
    } else {
        let template = Render {
            content: match ext {
                None => MarkupDisplay::new_unsafe(entry, Html),
                Some(extension) => highlight(&entry, extension)
                    .map(|h| MarkupDisplay::new_safe(h, Html))
                    .ok_or_else(|| Status::NotFound)?,
            },
        let content = match ext {
            None => MarkupDisplay::new_unsafe(entry, Html),
            Some(extension) => highlight(&entry, extension)
                .map(|h| MarkupDisplay::new_safe(h, Html))
                .ok_or_else(|| Status::NotFound)?,
        };

        template
        ShowPaste { content }
            .render()
            .map(|html| Content(ContentType::HTML, html))
            .map_err(|_| Status::InternalServerError)
@@ -113,6 +111,6 @@

fn main() {
    rocket::ignite()
        .mount("/", routes![index, submit, submit_raw, render])
        .mount("/", routes![index, submit, submit_raw, show_paste])
        .launch();
}