//! Every page and repeated fragment, as askama templates, which escape everything they are //! given unless it is marked `|safe`. Only HTML these templates or the Markdown and //! highlighting renderers produced is ever passed as safe. use askama::Template; /// A page with a heading, a sentence, and optionally a command to copy and a button. #[derive(Template)] #[template(path = "notice.html")] pub(crate) struct Notice<'a> { pub title: &'a str, pub signed_in: bool, pub heading: &'a str, pub message: &'a str, pub code: Option, pub link: Option<(&'a str, &'a str)>, } /// A repository's name, clone address and tabs. #[derive(Template)] #[template(path = "masthead.html")] pub(crate) struct Masthead<'a> { pub owner: &'a str, pub name: &'a str, pub home: String, /// "Public" or "Private", shown only when signed in. pub visibility: Option<&'static str>, /// Whether pushes are held to fast-forwards, shown only when signed in. pub protected: bool, pub description: Option, /// Each way to clone it: protocol and address. pub addresses: Vec<(&'static str, String)>, pub tabs: Vec, } pub(crate) struct Tab { pub href: String, pub current: bool, pub icon: String, pub label: &'static str, pub count: Option, } /// The branch and tag menu, then the path as breadcrumbs. #[derive(Template)] #[template(path = "locator.html")] pub(crate) struct Locator<'a> { pub branch_icon: String, pub chevron_icon: String, /// The reference as people see it. pub current: std::borrow::Cow<'a, str>, pub branches: Vec>, pub tags: Vec>, /// The repository root's link, when there is a path to show. pub root: Option, pub repo_name: &'a str, pub crumbs: Vec>, } pub(crate) struct MenuItem<'a> { pub href: String, pub current: bool, pub name: std::borrow::Cow<'a, str>, } /// One part of a path; the last has no link. pub(crate) struct Crumb<'a> { pub href: Option, pub name: std::borrow::Cow<'a, str>, } #[derive(Template)] #[template(path = "sha-link.html")] pub(crate) struct ShaLink<'a> { pub href: String, pub short: &'a str, } #[derive(Template)] #[template(path = "empty.html")] pub(crate) struct Empty<'a> { pub title: String, pub signed_in: bool, pub masthead: String, pub host: &'a str, pub owner: &'a str, pub name: &'a str, } /// Highlighted source with a gutter of line numbers. Each number is an anchor that links to /// itself (`#L`), and the `selected` lines are marked, so the stylesheet can highlight a /// linked line or range without any script. #[derive(Template)] #[template(path = "code.html")] pub(crate) struct Code<'a> { pub lines: usize, pub selected: Option<(usize, usize)>, pub code: &'a str, } impl Code<'_> { fn is_selected(&self, n: &usize) -> bool { self.selected.is_some_and(|(from, to)| (from..=to).contains(n)) } } /// Preview and Code links for a Markdown file. pub(crate) struct Views { pub preview: String, pub code: String, pub as_code: bool, } #[derive(Template)] #[template(path = "blob.html")] pub(crate) struct Blob<'a> { pub title: String, pub signed_in: bool, pub masthead: String, pub locator: String, pub file_icon: String, pub name: &'a str, pub facts: &'a str, pub views: Option, pub history: String, pub permalink: String, pub raw: String, pub content: &'a str, } pub(crate) struct TagRow<'a> { pub name: std::borrow::Cow<'a, str>, pub note: Option>, pub sha_link: String, pub when: String, pub browse: String, /// The tagged files as a `.tar.gz`. pub archive: String, /// A comparison with the previous tag, and its label. pub compare: Option<(String, String)>, } #[derive(Template)] #[template(path = "tags.html")] pub(crate) struct Tags<'a> { pub title: String, pub signed_in: bool, pub masthead: String, pub rows: Vec>, } /// One file of a commit's diff: its name and link, and its lines when they were read. pub(crate) struct DiffFile<'a> { pub href: String, pub path: std::borrow::Cow<'a, str>, pub status: &'static str, pub diff: Option<&'a super::views::FileDiff>, } #[derive(Template)] #[template(path = "diff.html")] pub(crate) struct Diff<'a> { pub file_count: String, pub totals: Option<(usize, usize)>, pub too_big: bool, /// What the changes are, for the note when they're too large: "This commit’s changes". pub what: &'static str, pub file_icon: String, pub files: Vec>, } #[derive(Template)] #[template(path = "account.html")] pub(crate) struct Account<'a> { pub title: &'a str, pub signed_in: bool, pub user: &'a str, pub message: &'a str, pub ok: bool, pub csrf: &'a str, pub min_password: usize, } #[derive(Template)] #[template(path = "login.html")] pub(super) struct SignIn<'a> { pub title: &'a str, pub signed_in: bool, pub next: &'a str, pub message: &'a str, } pub(super) struct TagLink<'a> { pub name: std::borrow::Cow<'a, str>, pub url: String, } #[derive(Template)] #[template(path = "compare.html")] pub(super) struct Compare<'a> { pub title: String, pub signed_in: bool, pub masthead: String, pub action: String, pub from: String, pub to: String, /// Branch and tag names the form suggests. pub refs: Vec, pub message: Option, pub summary: Option, pub swap: Option, pub rows: Vec>, pub more: Option, // Rendered by `Diff`, which escapes repository data. pub diff: Option, pub tag_icon: String, } pub(super) struct CommitRow<'a> { pub url: String, pub subject: String, pub short_id: String, pub author: String, pub when: String, pub tags: Vec>, } #[derive(Template)] #[template(path = "history.html")] pub(super) struct History<'a> { pub title: String, pub signed_in: bool, // Existing HTML renderers escape repository data inside these fragments. pub masthead: String, pub locator: String, pub tag_icon: String, pub rows: Vec>, /// A link comparing a branch with the default one, and its label. pub compare: Option<(String, String)>, pub newer: Option, pub older: Option, } pub(super) struct EntryCommit { pub url: String, pub subject: String, pub message: String, pub when: String, pub datetime: String, pub full_date: String, } #[derive(Template)] #[template(path = "tree-row.html")] pub(super) struct TreeRow<'a> { pub name: std::borrow::Cow<'a, str>, pub class: &'static str, pub icon: String, pub href: Option, pub short_id: &'a str, pub commit: Option, } pub(super) struct RepositoryRow { pub owner: String, pub name: String, pub public: bool, pub description: Option, pub subject: String, pub when: String, } #[derive(Template)] #[template(path = "repositories.html")] pub(super) struct Repositories<'a> { pub title: &'a str, pub signed_in: bool, pub count: String, /// The filter as typed, and how many repositories there are to filter. pub filter: String, pub total: usize, pub rows: Vec, pub branch: String, pub host: &'a str, } #[derive(Template)] #[template(path = "commit.html")] pub(super) struct Commit<'a> { pub title: &'a str, pub signed_in: bool, pub masthead: String, pub browse: String, pub message: &'a str, pub author: &'a str, pub email: &'a str, pub date: &'a str, pub short_id: &'a str, pub parent_links: String, pub diff: &'a str, } pub(super) struct TreeHead { pub author: String, pub subject: String, pub url: String, pub sha_link: String, pub when: String, pub history: String, } #[derive(Template)] #[template(path = "tree.html")] pub(super) struct Tree<'a> { pub title: String, pub signed_in: bool, pub masthead: String, pub locator: String, pub head: Option, pub up: Option, pub rows: Vec>, pub previous: Option, pub next: Option, pub readme: Option<(String, String)>, }