From bbf5bba490354b718f92478e9452e2832f08af6c Mon Sep 17 00:00:00 2001 From: Valentin Brandl Date: Mon, 25 Nov 2019 17:27:16 +0100 Subject: [PATCH] Reduce number of parameters --- src/main.rs | 30 ++++++++++++++++++++++-------- src/template.rs | 10 ++++++++++ templates/overview.rs.html | 11 +++++++---- 3 files changed, 39 insertions(+), 12 deletions(-) create mode 100644 src/template.rs diff --git a/src/main.rs b/src/main.rs index c4e6f7b..9667d10 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,12 +15,14 @@ mod count; mod error; mod service; mod statics; +mod template; use crate::{ cache::CacheState, error::{Error, Result}, service::{Bitbucket, FormService, GitHub, Gitlab, Service}, statics::{CLIENT, CSS, FAVICON, OPT, REPO_COUNT, VERSION_INFO}, + template::RepoInfo, }; use actix_web::{ error::ErrorBadRequest, @@ -271,18 +273,30 @@ fn overview( service_path, } => { let mut buf = Vec::new(); + let repo_info = RepoInfo { + commit_url: + &T::commit_url(&repo, &head), + commits, + domain: &OPT.domain, + head: &head, + hoc, + hoc_pretty: &hoc_pretty, + path: &service_path, + url: &url, + }; templates::overview( &mut buf, VERSION_INFO, REPO_COUNT.load(Ordering::Relaxed), - &OPT.domain, - &service_path, - &url, - hoc, - &hoc_pretty, - &head, - &T::commit_url(&repo, &head), - commits, + repo_info + // &OPT.domain, + // &service_path, + // &url, + // hoc, + // &hoc_pretty, + // &head, + // &T::commit_url(&repo, &head), + // commits, )?; let (tx, rx_body) = mpsc::unbounded(); diff --git a/src/template.rs b/src/template.rs new file mode 100644 index 0000000..163f074 --- /dev/null +++ b/src/template.rs @@ -0,0 +1,10 @@ +pub struct RepoInfo<'a> { + pub commit_url: &'a str, + pub commits: u64, + pub domain: &'a str, + pub head: &'a str, + pub hoc: u64, + pub hoc_pretty: &'a str, + pub path: &'a str, + pub url: &'a str, +} diff --git a/templates/overview.rs.html b/templates/overview.rs.html index 6b51ad2..7601983 100644 --- a/templates/overview.rs.html +++ b/templates/overview.rs.html @@ -1,13 +1,16 @@ @use super::base; @use crate::statics::VersionInfo; +@use crate::template::RepoInfo; -@(version_info: VersionInfo, repo_count: usize, domain: &str, path: &str, url: &str, hoc: u64, hoc_pretty: &str, head: &str, commit_url: &str, commits: u64) +@(version_info: VersionInfo, repo_count: usize, repo_info: RepoInfo) @:base("Hits-of-Code Badges", "Overview", {

-The project @url has @hoc_pretty (exactly @hoc) hits of code at -@head. The repository contains @commits commits. +The project @repo_info.url has +@repo_info.hoc_pretty (exactly @repo_info.hoc) hits of code at +@repo_info.head. The repository contains +@repo_info.commits commits.

@@ -15,6 +18,6 @@ To include the badge in your readme, use the following markdown:

-[![Hits-of-Code](https://@domain/@path)](https://@domain/view/@path)
+[![Hits-of-Code](https://@repo_info.domain/@repo_info.path)](https://@repo_info.domain/view/@repo_info.path)
 
}, version_info, repo_count)