Port to Rocket 0.5.0-rc2
This commit is contained in:
parent
c3ae8ca62a
commit
da5179d05a
File diff suppressed because it is too large
Load Diff
16
Cargo.toml
16
Cargo.toml
|
@ -8,16 +8,16 @@ a family or group of friends.
|
||||||
"""
|
"""
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
edition = "2018"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
comrak = "0.7.0"
|
Inflector = "0.11.4"
|
||||||
|
comrak = "0.14.0"
|
||||||
glob = "0.3.0"
|
glob = "0.3.0"
|
||||||
Inflector = "*"
|
rocket = { version = "0.5.0-rc.2", features = ["json"] }
|
||||||
rocket = { version = "0.5.0-rc.1", features = ["json"] }
|
rocket_dyn_templates = { version = "0.1.0-rc.2", features = ["tera"] }
|
||||||
rocket_dyn_templates = { version = "0.1.0-rc.1", features = ["tera"] }
|
toml = "0.5.9"
|
||||||
toml = "0.5"
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
serde = "1.0"
|
serde = "1.0.145"
|
||||||
serde_json = "1.0"
|
serde_json = "1.0.86"
|
||||||
|
|
|
@ -40,14 +40,13 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn index() {
|
fn index() {
|
||||||
let client = Client::untracked(crate::rocket(Some("test"))).unwrap();
|
let client = Client::untracked(crate::build_rocket(Some("test"))).unwrap();
|
||||||
|
|
||||||
// Try to get the index and verify the body
|
// Try to get the index and verify the body
|
||||||
let res = client.get("/").header(Accept::HTML).dispatch();
|
let res = client.get("/").header(Accept::HTML).dispatch();
|
||||||
assert_eq!(res.status(), Status::Ok);
|
assert_eq!(res.status(), Status::Ok);
|
||||||
|
|
||||||
let body = res.into_string().unwrap();
|
let body = res.into_string().unwrap();
|
||||||
println!("body: {}", body);
|
|
||||||
assert!(body.contains("<span id=\"note-name\">Test</span>"));
|
assert!(body.contains("<span id=\"note-name\">Test</span>"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn index() {
|
fn index() {
|
||||||
let client = Client::untracked(crate::rocket(Some("test"))).unwrap();
|
let client = Client::untracked(crate::build_rocket(Some("test"))).unwrap();
|
||||||
|
|
||||||
// Try to get all the notes
|
// Try to get all the notes
|
||||||
let res = client.get("/notes").header(Accept::JSON).dispatch();
|
let res = client.get("/notes").header(Accept::JSON).dispatch();
|
||||||
|
@ -72,7 +72,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn show_html() {
|
fn show_html() {
|
||||||
let client = Client::untracked(crate::rocket(Some("test"))).unwrap();
|
let client = Client::untracked(crate::build_rocket(Some("test"))).unwrap();
|
||||||
|
|
||||||
// Try to get the note and verify the body
|
// Try to get the note and verify the body
|
||||||
let res = client.get("/notes/test").header(Accept::HTML).dispatch();
|
let res = client.get("/notes/test").header(Accept::HTML).dispatch();
|
||||||
|
@ -93,7 +93,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn show_json() {
|
fn show_json() {
|
||||||
let client = Client::untracked(crate::rocket(Some("test"))).unwrap();
|
let client = Client::untracked(crate::build_rocket(Some("test"))).unwrap();
|
||||||
|
|
||||||
// Try to get the note and verify the body
|
// Try to get the note and verify the body
|
||||||
let res = client.get("/notes/test").header(Accept::JSON).dispatch();
|
let res = client.get("/notes/test").header(Accept::JSON).dispatch();
|
||||||
|
@ -120,7 +120,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn update() {
|
fn update() {
|
||||||
let client = Client::untracked(crate::rocket(Some("test"))).unwrap();
|
let client = Client::untracked(crate::build_rocket(Some("test"))).unwrap();
|
||||||
|
|
||||||
// Try to get the note and determine what to change it to
|
// Try to get the note and determine what to change it to
|
||||||
let res = client
|
let res = client
|
||||||
|
|
10
src/main.rs
10
src/main.rs
|
@ -17,7 +17,7 @@ pub struct Config {
|
||||||
title: String,
|
title: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rocket(notes_path: Option<&str>) -> Rocket<Build> {
|
fn build_rocket(notes_path: Option<&str>) -> Rocket<Build> {
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
@ -51,9 +51,7 @@ fn rocket(notes_path: Option<&str>) -> Rocket<Build> {
|
||||||
.attach(Template::fairing())
|
.attach(Template::fairing())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rocket::main]
|
#[rocket::launch]
|
||||||
async fn main() -> Result<(), rocket::Error> {
|
fn rocket() -> _ {
|
||||||
rocket(None).launch().await?;
|
build_rocket(None)
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ pub struct Note {
|
||||||
/// The ID of the note (unique string)
|
/// The ID of the note (unique string)
|
||||||
pub id: String,
|
pub id: String,
|
||||||
/// The index of the note (unique number)
|
/// The index of the note (unique number)
|
||||||
pub index: i8,
|
pub index: usize,
|
||||||
/// The raw note data
|
/// The raw note data
|
||||||
pub data: String,
|
pub data: String,
|
||||||
/// The time the note was last modified
|
/// The time the note was last modified
|
||||||
|
@ -29,10 +29,10 @@ pub struct Note {
|
||||||
impl Note {
|
impl Note {
|
||||||
pub fn to_html(&self) -> String {
|
pub fn to_html(&self) -> String {
|
||||||
let mut options = comrak::ComrakOptions::default();
|
let mut options = comrak::ComrakOptions::default();
|
||||||
options.ext_strikethrough = true;
|
options.extension.strikethrough = true;
|
||||||
options.ext_tagfilter = true;
|
options.extension.tagfilter = true;
|
||||||
options.ext_autolink = true;
|
options.extension.autolink = true;
|
||||||
options.ext_tasklist = true;
|
options.extension.tasklist = true;
|
||||||
|
|
||||||
comrak::markdown_to_html(&self.data, &options)
|
comrak::markdown_to_html(&self.data, &options)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue