aboutsummaryrefslogtreecommitdiff
path: root/src/templ_data/repo.rs
//! 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>,
    }
}