From d320259fe858b5d80f5020502fda01a07466e486 Mon Sep 17 00:00:00 2001 From: Sam Rijs Date: Sat, 27 Jan 2018 22:49:43 +1100 Subject: [PATCH] link to repo site in headline --- assets/static/style.css | 4 ++++ src/models/repo.rs | 29 ++++++++++++++++++----------- src/server/views/status_html.rs | 4 +++- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/assets/static/style.css b/assets/static/style.css index 535b6d0..64817b8 100644 --- a/assets/static/style.css +++ b/assets/static/style.css @@ -35,6 +35,10 @@ code { color: #555; } +h1 a { + text-decoration: none; +} + h1 code { letter-spacing: -0.02em; } diff --git a/src/models/repo.rs b/src/models/repo.rs index db5617c..b84a901 100644 --- a/src/models/repo.rs +++ b/src/models/repo.rs @@ -20,28 +20,35 @@ impl RepoPath { #[derive(Debug)] pub struct RepoValidationError; -#[derive(Clone)] -pub struct RepoSite(String); +#[derive(Clone, Copy)] +pub enum RepoSite { + Github +} + +impl RepoSite { + pub fn to_base_uri(&self) -> &'static str { + match self { + &RepoSite::Github => "https://github.com" + } + } +} impl FromStr for RepoSite { type Err = RepoValidationError; fn from_str(input: &str) -> Result { - let is_valid = input.chars().all(|c| { - c.is_ascii_alphanumeric() || c == '.' - }); - - if !is_valid { - Err(RepoValidationError) - } else { - Ok(RepoSite(input.to_string())) + match input { + "github" => Ok(RepoSite::Github), + _ => Err(RepoValidationError) } } } impl AsRef for RepoSite { fn as_ref(&self) -> &str { - self.0.as_ref() + match self { + &RepoSite::Github => "github" + } } } diff --git a/src/server/views/status_html.rs b/src/server/views/status_html.rs index 3f7f3c8..327880f 100644 --- a/src/server/views/status_html.rs +++ b/src/server/views/status_html.rs @@ -58,7 +58,9 @@ pub fn status_html(analysis_outcome: AnalyzeDependenciesOutcome, repo_path: Repo header { h1 { "Dependency status for " - code (format!("{}/{}", repo_path.qual.as_ref(), repo_path.name.as_ref())) + a href=(format!("{}/{}/{}", repo_path.site.to_base_uri(), repo_path.qual.as_ref(), repo_path.name.as_ref())) { + code (format!("{}/{}", repo_path.qual.as_ref(), repo_path.name.as_ref())) + } } img src=(format!("/{}/status.svg", self_path));