diff options
author | Katharina Fey <kookie@spacekookie.de> | 2020-10-31 18:57:39 +0100 |
---|---|---|
committer | Mx Kookie <kookie@spacekookie.de> | 2020-12-21 05:10:08 +0100 |
commit | 9dacf748651ea7139c0e9f3dee9ae66d949bf73f (patch) | |
tree | 7101bc20d5a531218ccd1b4cb9e04c67995f6d0e /apps/servers/octopus/src/templ_data | |
parent | 4e09fe2509904ee64d2470ca8d41006d51e4ffd6 (diff) |
Add 'apps/servers/octopus/' from commit '623954d19fdf0dca47db319e5c88ee561aa8d25c'
git-subtree-dir: apps/servers/octopus
git-subtree-mainline: 4e09fe2509904ee64d2470ca8d41006d51e4ffd6
git-subtree-split: 623954d19fdf0dca47db319e5c88ee561aa8d25c
Diffstat (limited to 'apps/servers/octopus/src/templ_data')
-rw-r--r-- | apps/servers/octopus/src/templ_data/files.rs | 13 | ||||
-rw-r--r-- | apps/servers/octopus/src/templ_data/mod.rs | 38 | ||||
-rw-r--r-- | apps/servers/octopus/src/templ_data/overview.rs | 11 | ||||
-rw-r--r-- | apps/servers/octopus/src/templ_data/repo.rs | 80 |
4 files changed, 142 insertions, 0 deletions
diff --git a/apps/servers/octopus/src/templ_data/files.rs b/apps/servers/octopus/src/templ_data/files.rs new file mode 100644 index 000000000000..27a5bde99e5d --- /dev/null +++ b/apps/servers/octopus/src/templ_data/files.rs @@ -0,0 +1,13 @@ +//! File browser template data + +use super::BaseData; +use askama::Template; + +// This struct needs escapng=none to render README files it encounters along the way +#[derive(Template)] +#[template(path = "files.html", escape = "none")] +pub(crate) struct Files { + pub base: BaseData, + pub path: String, + pub readme: Option<String>, +} diff --git a/apps/servers/octopus/src/templ_data/mod.rs b/apps/servers/octopus/src/templ_data/mod.rs new file mode 100644 index 000000000000..7645e95ef824 --- /dev/null +++ b/apps/servers/octopus/src/templ_data/mod.rs @@ -0,0 +1,38 @@ +//! 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 overview; +pub(crate) mod files; + +use std::env; + +/// A basic application wide template structure +pub(crate) struct BaseData { + pub version: String, + pub source: String, + pub siteurl: String, + pub sitename: String, + pub has_wiki: bool, +} + +impl Default for BaseData { + fn default() -> Self { + Self { + version: env!("CARGO_PKG_VERSION").into(), + source: env::var("_OCTOPUS_SOURCE") + .unwrap_or("https://dev.spacekookie.de/web/octopus".to_string()), + siteurl: env::var("_OCTOPUS_SITE_URL").unwrap_or("localhost:8080".to_string()), + sitename: env::var("_OCTOPUS_SITE_NAME").unwrap_or("test-octopus".to_string()), + has_wiki: true, + } + } +} diff --git a/apps/servers/octopus/src/templ_data/overview.rs b/apps/servers/octopus/src/templ_data/overview.rs new file mode 100644 index 000000000000..693db0a85e77 --- /dev/null +++ b/apps/servers/octopus/src/templ_data/overview.rs @@ -0,0 +1,11 @@ +//! Template data for the main overview + +use super::BaseData; +use askama::Template; + +#[derive(Template)] +#[template(path = "index.html", escape = "none")] +pub(crate) struct Index { + pub base: BaseData, + pub readme: String, +} diff --git a/apps/servers/octopus/src/templ_data/repo.rs b/apps/servers/octopus/src/templ_data/repo.rs new file mode 100644 index 000000000000..989c9b404620 --- /dev/null +++ b/apps/servers/octopus/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>, + } +} |