aboutsummaryrefslogtreecommitdiff
path: root/src/templ_data
diff options
context:
space:
mode:
authorKatharina Fey <kookie@spacekookie.de>2020-06-22 06:23:04 +0200
committerKatharina Fey <kookie@spacekookie.de>2020-06-22 06:23:04 +0200
commite30713b84bc9e66f7a8e8d2f51e953472cac28e4 (patch)
tree3098b1c77a978dcad0c828f57386d1c8999aa26b /src/templ_data
parent84a9a0ccee713e26a28ff5e54ea3776085d93b5f (diff)
Committing all the libgit2 progress before throwing it away
I don't think libgit2 is the way forward to make any of this work. There's so much work involved in parsing the git k-v store, and the library itself is essentially of zero help for most of the heavy lifting.
Diffstat (limited to 'src/templ_data')
-rw-r--r--src/templ_data/mod.rs30
-rw-r--r--src/templ_data/repo.rs80
2 files changed, 110 insertions, 0 deletions
diff --git a/src/templ_data/mod.rs b/src/templ_data/mod.rs
new file mode 100644
index 0000000..6c93266
--- /dev/null
+++ b/src/templ_data/mod.rs
@@ -0,0 +1,30 @@
+//! Octopus template data structures
+//!
+//! All pages are generated by the server via template files that have
+//! data inputs. Because the templates follow a well-defined
+//! structure (i.e. `core` extended by `<type>/base` extended by
+//! `<type>/<page>`, the structure of these template data structures
+//! is the same.
+//!
+//! The actual page initialisation and rendering is nested in the
+//! `page` module, which then uses the appropriate template structures
+//! defined here.
+
+pub(crate) mod repo;
+
+/// A basic application wide template structure
+pub(crate) struct BaseData {
+ pub version: String,
+ pub source: String,
+ pub url: String,
+}
+
+impl Default for BaseData {
+ fn default() -> Self {
+ Self {
+ version: "0.2.0".into(),
+ source: "".into(),
+ url: "http://localhost:8080".into(),
+ }
+ }
+}
diff --git a/src/templ_data/repo.rs b/src/templ_data/repo.rs
new file mode 100644
index 0000000..989c9b4
--- /dev/null
+++ b/src/templ_data/repo.rs
@@ -0,0 +1,80 @@
+//! Repository specific template data
+
+use std::collections::BTreeMap;
+
+/// A simple overview of a repository
+///
+/// This type can be generated by the octopus Repository state wrapper
+#[derive(Clone)]
+pub(crate) struct RepoData {
+ pub owner: String,
+ pub name: String,
+ pub tagline: String,
+ pub num_commit: usize,
+ pub num_branch: usize,
+ pub num_tag: usize,
+ pub num_contributor: usize,
+ pub size: String,
+ pub logo: String,
+}
+
+/// Data about an individual commit
+#[derive(Clone)]
+pub(crate) struct CommitData {
+ pub hash: String,
+ pub message: String,
+ pub author: String,
+ pub date: String,
+ pub diff: (usize, usize),
+}
+
+/// Data about a branch
+#[derive(Clone)]
+pub(crate) struct BranchData {
+ pub name: String,
+ pub last_commit: CommitData,
+}
+
+/// Data about a repository tree
+#[derive(Clone)]
+pub(crate) struct TreeData {
+ /// The path segments in the current directory
+ curr_dir: Vec<String>,
+ /// The set of children in this tree segment
+ files: BTreeMap<String, FileData>,
+}
+
+/// Information about a concrete file in a tree
+#[derive(Clone)]
+pub(crate) struct FileData {
+ name: String,
+ last_commit: CommitData,
+ is_directory: bool,
+}
+
+pub(crate) mod pages {
+ use super::*;
+ use crate::templ_data::BaseData;
+ use askama::Template;
+
+ #[derive(Template)]
+ #[template(path = "repo/about.html")]
+ pub(crate) struct About {
+ pub base: BaseData,
+ pub repo: RepoData,
+
+ // Template specific
+ pub readme: String,
+ }
+
+ #[derive(Template)]
+ #[template(path = "repo/details.html")]
+ pub(crate) struct Details {
+ pub base: BaseData,
+ pub repo: RepoData,
+
+ // Template specifics
+ pub branches: Vec<BranchData>,
+ pub commits: Vec<CommitData>,
+ }
+}