From e30713b84bc9e66f7a8e8d2f51e953472cac28e4 Mon Sep 17 00:00:00 2001 From: Katharina Fey Date: Mon, 22 Jun 2020 06:23:04 +0200 Subject: 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. --- src/templ_data/mod.rs | 30 +++++++++++++++++++ src/templ_data/repo.rs | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 src/templ_data/mod.rs create mode 100644 src/templ_data/repo.rs (limited to 'src/templ_data') 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 `/base` extended by +//! `/`, 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, + /// The set of children in this tree segment + files: BTreeMap, +} + +/// 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, + pub commits: Vec, + } +} -- cgit v1.2.3