about summary refs log tree commit diff
path: root/kittybox-rs/templates/src
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2022-07-07 00:34:43 +0300
committerVika <vika@fireburn.ru>2022-07-07 00:36:39 +0300
commit7ddb7eddec3b928947b52f715aaf4821a818ebee (patch)
treea2274a6caedf4c2b1f11469097a51dddd68e774c /kittybox-rs/templates/src
parent7f23ec84bc05c236c1bf40c2f0d72412af711516 (diff)
downloadkittybox-7ddb7eddec3b928947b52f715aaf4821a818ebee.tar.zst
format using rustfmt
Diffstat (limited to 'kittybox-rs/templates/src')
-rw-r--r--kittybox-rs/templates/src/lib.rs116
-rw-r--r--kittybox-rs/templates/src/onboarding.rs6
-rw-r--r--kittybox-rs/templates/src/templates.rs2
3 files changed, 55 insertions, 69 deletions
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::<Word>(), rand::random::<Word>(), rand::random::<Word>()
+            rand::random::<Word>(),
+            rand::random::<Word>(),
+            rand::random::<Word>()
         );
-        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::<Paragraph>();
 
@@ -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<RefCell<Item>>
-    ) {
+    fn check_dt_published(mf2: &serde_json::Value, item: &Rc<RefCell<Item>>) {
         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::<FixedOffset>::from_utc(ndt, offset);
 
             let expected: DateTime<FixedOffset> = 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<RefCell<Item>>
-    ) {
+    fn check_e_content(mf2: &serde_json::Value, item: &Rc<RefCell<Item>>) {
         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::<Domain>().to_string(),
-            PostType::Note
-        );
+        let mf2 = gen_random_post(&rand::random::<Domain>().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::<Domain>().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::<Domain>().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::<Domain>().to_string(),
-                PostType::Note
+                PostType::Note,
             )),
             PostType::LikeOfLink(format!(
                 "https://{}/posts/{}-{}-{}",
@@ -302,19 +286,15 @@ mod tests {
                 &rand::random::<Word>(),
                 &rand::random::<Word>(),
                 &rand::random::<Word>(),
-            ))
+            )),
         ] {
-            let mf2 = gen_random_post(
-                &rand::random::<Domain>().to_string(),
-                likeof
-            );
-            let url: Url = mf2.pointer("/properties/uid/0")
+            let mf2 = gen_random_post(&rand::random::<Domain>().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::<Url>().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("<!-- do cats even have souls? I'm not sure. But this code won't steal their souls anyway. -->")
                 }
                 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;