From 7ddb7eddec3b928947b52f715aaf4821a818ebee Mon Sep 17 00:00:00 2001 From: Vika Date: Thu, 7 Jul 2022 00:34:43 +0300 Subject: format using rustfmt --- kittybox-rs/templates/src/lib.rs | 116 ++++++++++++++------------------ kittybox-rs/templates/src/onboarding.rs | 6 +- kittybox-rs/templates/src/templates.rs | 2 +- 3 files changed, 55 insertions(+), 69 deletions(-) (limited to 'kittybox-rs/templates/src') diff --git a/kittybox-rs/templates/src/lib.rs b/kittybox-rs/templates/src/lib.rs index 39f1075..8e9abba 100644 --- a/kittybox-rs/templates/src/lib.rs +++ b/kittybox-rs/templates/src/lib.rs @@ -1,5 +1,5 @@ mod templates; -pub use templates::{ErrorPage, MainPage, Template, POSTS_PER_PAGE, Entry, VCard, Feed}; +pub use templates::{Entry, ErrorPage, Feed, MainPage, Template, VCard, POSTS_PER_PAGE}; mod onboarding; pub use onboarding::OnboardingPage; mod login; @@ -7,12 +7,12 @@ pub use login::LoginPage; #[cfg(test)] mod tests { + use faker_rand::en_us::internet::Domain; use faker_rand::lorem::Word; - use serde_json::json; use microformats::types::{Document, Item, PropertyValue, Url}; + use serde_json::json; use std::cell::RefCell; use std::rc::Rc; - use faker_rand::en_us::internet::Domain; enum PostType { Note, @@ -20,7 +20,7 @@ mod tests { ReplyTo(serde_json::Value), ReplyToLink(String), LikeOf(serde_json::Value), - LikeOfLink(String) + LikeOfLink(String), } fn gen_hcard(domain: &str) -> serde_json::Value { @@ -36,7 +36,7 @@ mod tests { } }) } - + fn gen_random_post(domain: &str, kind: PostType) -> serde_json::Value { use faker_rand::lorem::{Paragraph, Sentence}; @@ -46,13 +46,14 @@ mod tests { "value": content.to_string() }) } - + let uid = format!( "https://{domain}/posts/{}-{}-{}", - rand::random::(), rand::random::(), rand::random::() + rand::random::(), + rand::random::(), + rand::random::() ); - let dt = chrono::offset::Local::now() - .to_rfc3339_opts(chrono::SecondsFormat::Secs, true); + let dt = chrono::offset::Local::now().to_rfc3339_opts(chrono::SecondsFormat::Secs, true); match kind { PostType::Note => { @@ -99,7 +100,7 @@ mod tests { }] } }) - }, + } PostType::ReplyToLink(link) => { let content = rand::random::(); @@ -113,7 +114,7 @@ mod tests { "in-reply-to": [link] } }) - }, + } PostType::LikeOf(ctx) => { json!({ "type": ["h-entry"], @@ -127,7 +128,7 @@ mod tests { }] } }) - }, + } PostType::LikeOfLink(link) => { json!({ "type": ["h-entry"], @@ -142,20 +143,15 @@ mod tests { } } - fn check_dt_published( - mf2: &serde_json::Value, - item: &Rc> - ) { + fn check_dt_published(mf2: &serde_json::Value, item: &Rc>) { use microformats::types::temporal::Value as TemporalValue; let _item = item.borrow(); let props = _item.properties.borrow(); assert!(props.contains_key("published")); - if let Some(PropertyValue::Temporal( - TemporalValue::Timestamp(item) - )) = props.get("published") - .and_then(|v| v.first()) + if let Some(PropertyValue::Temporal(TemporalValue::Timestamp(item))) = + props.get("published").and_then(|v| v.first()) { use chrono::{DateTime, FixedOffset, NaiveDateTime}; @@ -171,8 +167,9 @@ mod tests { let dt = DateTime::::from_utc(ndt, offset); let expected: DateTime = chrono::DateTime::parse_from_rfc3339( - mf2["properties"]["published"][0].as_str().unwrap() - ).unwrap(); + mf2["properties"]["published"][0].as_str().unwrap(), + ) + .unwrap(); assert_eq!(dt, expected); } else { @@ -180,17 +177,12 @@ mod tests { } } - fn check_e_content( - mf2: &serde_json::Value, - item: &Rc> - ) { + fn check_e_content(mf2: &serde_json::Value, item: &Rc>) { let _item = item.borrow(); let props = _item.properties.borrow(); assert!(props.contains_key("content")); - if let Some(PropertyValue::Fragment(content)) = - props.get("content") - .and_then(|v| v.first()) + if let Some(PropertyValue::Fragment(content)) = props.get("content").and_then(|v| v.first()) { assert_eq!( content.html, @@ -199,7 +191,6 @@ mod tests { } else { unreachable!() } - } #[test] @@ -207,16 +198,12 @@ mod tests { fn test_note() { test_logger::ensure_env_logger_initialized(); - let mf2 = gen_random_post( - &rand::random::().to_string(), - PostType::Note - ); + let mf2 = gen_random_post(&rand::random::().to_string(), PostType::Note); - let html = crate::templates::Entry { - post: &mf2 - }.to_string(); + let html = crate::templates::Entry { post: &mf2 }.to_string(); - let url: Url = mf2.pointer("/properties/uid/0") + let url: Url = mf2 + .pointer("/properties/uid/0") .and_then(|i| i.as_str()) .and_then(|u| u.parse().ok()) .unwrap(); @@ -230,13 +217,13 @@ mod tests { check_dt_published(&mf2, &item); assert!(props.contains_key("uid")); assert!(props.contains_key("url")); - assert!(props.get("url") - .unwrap() - .iter() - .any(|i| i == props.get("uid").and_then(|v| v.first()).unwrap())); + assert!(props + .get("url") + .unwrap() + .iter() + .any(|i| i == props.get("uid").and_then(|v| v.first()).unwrap())); // XXX: fails because of https://gitlab.com/maxburon/microformats-parser/-/issues/7 assert!(!props.contains_key("name")); - } else { unreachable!() } @@ -246,14 +233,10 @@ mod tests { fn test_article() { test_logger::ensure_env_logger_initialized(); - let mf2 = gen_random_post( - &rand::random::().to_string(), - PostType::Article - ); - let html = crate::templates::Entry { - post: &mf2 - }.to_string(); - let url: Url = mf2.pointer("/properties/uid/0") + let mf2 = gen_random_post(&rand::random::().to_string(), PostType::Article); + let html = crate::templates::Entry { post: &mf2 }.to_string(); + let url: Url = mf2 + .pointer("/properties/uid/0") .and_then(|i| i.as_str()) .and_then(|u| u.parse().ok()) .unwrap(); @@ -267,10 +250,11 @@ mod tests { check_dt_published(&mf2, &item); assert!(props.contains_key("uid")); assert!(props.contains_key("url")); - assert!(props.get("url") - .unwrap() - .iter() - .any(|i| i == props.get("uid").and_then(|v| v.first()).unwrap())); + assert!(props + .get("url") + .unwrap() + .iter() + .any(|i| i == props.get("uid").and_then(|v| v.first()).unwrap())); assert!(props.contains_key("name")); if let Some(PropertyValue::Plain(name)) = props.get("name").and_then(|v| v.first()) { assert_eq!( @@ -294,7 +278,7 @@ mod tests { for likeof in [ PostType::LikeOf(gen_random_post( &rand::random::().to_string(), - PostType::Note + PostType::Note, )), PostType::LikeOfLink(format!( "https://{}/posts/{}-{}-{}", @@ -302,19 +286,15 @@ mod tests { &rand::random::(), &rand::random::(), &rand::random::(), - )) + )), ] { - let mf2 = gen_random_post( - &rand::random::().to_string(), - likeof - ); - let url: Url = mf2.pointer("/properties/uid/0") + let mf2 = gen_random_post(&rand::random::().to_string(), likeof); + let url: Url = mf2 + .pointer("/properties/uid/0") .and_then(|i| i.as_str()) .and_then(|u| u.parse().ok()) .unwrap(); - let html = crate::templates::Entry { - post: &mf2 - }.to_string(); + let html = crate::templates::Entry { post: &mf2 }.to_string(); let parsed: Document = microformats::from_html(&html, url.clone()).unwrap(); if let Some(item) = parsed.items.get(0) { @@ -329,7 +309,9 @@ mod tests { url, &mf2.pointer("/properties/like-of/0") .and_then(|i| i.as_str()) - .or_else(|| mf2.pointer("/properties/like-of/0/properties/uid/0").and_then(|i| i.as_str())) + .or_else(|| mf2 + .pointer("/properties/like-of/0/properties/uid/0") + .and_then(|i| i.as_str())) .and_then(|u| u.parse::().ok()) .unwrap() ); @@ -337,7 +319,7 @@ mod tests { Some(PropertyValue::Item(_cite)) => { todo!() } - other => panic!("Unexpected value in like-of: {:?}", other) + other => panic!("Unexpected value in like-of: {:?}", other), } } else { unreachable!() diff --git a/kittybox-rs/templates/src/onboarding.rs b/kittybox-rs/templates/src/onboarding.rs index 5a9f226..e2f07df 100644 --- a/kittybox-rs/templates/src/onboarding.rs +++ b/kittybox-rs/templates/src/onboarding.rs @@ -29,7 +29,11 @@ markup::define! { @markup::raw("") } hr; - p { "In other words: " b { "please enable JavaScript for this page to work properly." } small { "sorry T__T" } } + p { + "In other words: " + b { "please enable JavaScript for this page to work properly." } + small { "sorry T__T" } + } } ul #progressbar[style="display: none"] { li #intro { "Introduction" } diff --git a/kittybox-rs/templates/src/templates.rs b/kittybox-rs/templates/src/templates.rs index b084fbd..0b1db28 100644 --- a/kittybox-rs/templates/src/templates.rs +++ b/kittybox-rs/templates/src/templates.rs @@ -1,6 +1,6 @@ -use kittybox_util::{MicropubChannel, IndiewebEndpoints}; use ellipse::Ellipse; use http::StatusCode; +use kittybox_util::{IndiewebEndpoints, MicropubChannel}; use log::error; pub static POSTS_PER_PAGE: usize = 20; -- cgit 1.4.1