about summary refs log tree commit diff
path: root/templates-neo
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2023-08-08 14:57:28 +0300
committerVika <vika@fireburn.ru>2023-08-08 14:57:28 +0300
commit27b5bcc274675eab956e70bc59ba3e137e5aa676 (patch)
treec931a316ea47c9a148c684baace8c4c34271e5a8 /templates-neo
parentfbea42e5494c96174097bf3809a5b53d11d68a48 (diff)
downloadkittybox-27b5bcc274675eab956e70bc59ba3e137e5aa676.tar.zst
templates-neo: add a test CLI that renders entries
This allows interactively testing the markup.
Diffstat (limited to 'templates-neo')
-rw-r--r--templates-neo/src/main.rs16
-rw-r--r--templates-neo/src/mf2.rs12
2 files changed, 22 insertions, 6 deletions
diff --git a/templates-neo/src/main.rs b/templates-neo/src/main.rs
new file mode 100644
index 0000000..54afbb8
--- /dev/null
+++ b/templates-neo/src/main.rs
@@ -0,0 +1,16 @@
+use std::io::Write;
+
+use kittybox_html::mf2::Entry;
+
+
+fn main() {
+    let mf2 = serde_json::from_reader::<_, microformats::types::Item>(std::io::stdin()).unwrap();
+    let entry = Entry::try_from(mf2).unwrap();
+
+    let mut article = html::content::Article::builder();
+    entry.build(&mut article);
+
+    let mut stdout = std::io::stdout().lock();
+    stdout.write_all(article.build().to_string().as_bytes()).unwrap();
+    stdout.write_all(b"\n").unwrap();
+}
\ No newline at end of file
diff --git a/templates-neo/src/mf2.rs b/templates-neo/src/mf2.rs
index c4d49a2..e59b51c 100644
--- a/templates-neo/src/mf2.rs
+++ b/templates-neo/src/mf2.rs
@@ -18,7 +18,7 @@ pub enum Error {
         got: PropertyValue
     },
     #[error("missing property: {0}")]
-    MissingProperty(&'static str)
+    MissingProperty(&'static str),
 }
 
 pub enum Image {
@@ -30,7 +30,7 @@ pub enum Image {
 }
 
 impl Image {
-    fn build(self, img: &mut html::media::builders::ImageBuilder) -> &mut html::media::builders::ImageBuilder {
+    pub fn build(self, img: &mut html::media::builders::ImageBuilder) -> &mut html::media::builders::ImageBuilder {
         match self {
             Image::Plain(url) => img.src(String::from(url)),
             Image::Accessible { src, alt } => img.src(String::from(src)).alt(alt)
@@ -132,7 +132,7 @@ impl TryFrom<Item> for Card {
 }
 
 impl Card {
-    fn build_section(self, section: &mut html::content::builders::SectionBuilder) -> &mut html::content::builders::SectionBuilder {
+    pub fn build_section(self, section: &mut html::content::builders::SectionBuilder) -> &mut html::content::builders::SectionBuilder {
         section
             .class("mini-h-card")
             .anchor(|a| a
@@ -143,7 +143,7 @@ impl Card {
             )
     }
 
-    fn build(self, article: &mut html::content::builders::ArticleBuilder) -> &mut html::content::builders::ArticleBuilder {
+    pub fn build(self, article: &mut html::content::builders::ArticleBuilder) -> &mut html::content::builders::ArticleBuilder {
         let urls: Vec<_> = self.urls.into_iter().filter(|u| *u != self.uid).collect();
 
         article
@@ -373,7 +373,7 @@ impl TryFrom<Item> for Entry {
 }
 
 impl Entry {
-    fn build(self, article: &mut ArticleBuilder) -> &mut ArticleBuilder {
+    pub fn build(self, article: &mut ArticleBuilder) -> &mut ArticleBuilder {
         article
             .class("h-entry")
             .header(|header| header
@@ -406,7 +406,7 @@ impl Entry {
                             })
                         )
                     })
-                )
+            )
             .main(|main| {
                 if let Some(lang) = self.content.0.lang {
                     main.lang(lang);