summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main.rs5
-rw-r--r--src/works/mod.rs2
-rw-r--r--src/works/stories.rs19
-rw-r--r--stories.json9
4 files changed, 30 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs
index b3e907d..4be987f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,6 +1,6 @@
use tera::{Context, Tera};
-use self::works::Work;
+use crate::works::Works;
mod works;
@@ -29,4 +29,7 @@ fn main() {
let stories = works::stories::Stories::new_from_file(file);
println!("Stories: {:?}", stories);
+
+ let context = stories.create_tera_context();
+ println!("{:?}", context);
}
diff --git a/src/works/mod.rs b/src/works/mod.rs
index ab7bcf5..f399fdd 100644
--- a/src/works/mod.rs
+++ b/src/works/mod.rs
@@ -9,4 +9,6 @@ pub trait Works: for<'a> Deserialize<'a> {
Err(err) => panic!("Trying to create work from JSON File - {:?}", err),
}
}
+
+ fn create_tera_context(&self) -> Vec<tera::Context>;
}
diff --git a/src/works/stories.rs b/src/works/stories.rs
index b437fb4..5d96ed8 100644
--- a/src/works/stories.rs
+++ b/src/works/stories.rs
@@ -1,10 +1,11 @@
-use serde::Deserialize;
+use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize)]
pub struct Stories(pub Vec<Story>);
-#[derive(Debug, Deserialize)]
+#[derive(Debug, Deserialize, Serialize)]
pub struct Story {
+ pub id: u8,
pub title: String,
pub description: String,
pub path_to_document: String,
@@ -12,9 +13,19 @@ pub struct Story {
pub language: Language,
}
-impl super::Works for Stories {}
+impl super::Works for Stories {
+ fn create_tera_context(&self) -> Vec<tera::Context> {
+ let mut context = Vec::new();
+ for story in self.0.iter() {
+ context.push(
+ tera::Context::from_serialize(&story).expect("Trying to serialize to tera context"),
+ );
+ }
+ context
+ }
+}
-#[derive(Deserialize, Debug)]
+#[derive(Deserialize, Serialize, Debug)]
pub enum Language {
German,
English,
diff --git a/stories.json b/stories.json
index 6ee46a6..2744441 100644
--- a/stories.json
+++ b/stories.json
@@ -1,9 +1,18 @@
[
{
+ "id": 1,
"title": "Test",
"description": "Test",
"path_to_document": "Test",
"slug": "Test",
"language": "German"
+ },
+ {
+ "id": 2,
+ "title": "Test2",
+ "description": "Test2",
+ "path_to_document": "Test2",
+ "slug": "Test2",
+ "language": "German"
}
]