-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add render_name module for handling different patterns name…
…s in markdown render
- Loading branch information
Showing
5 changed files
with
65 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
pub mod render; | ||
pub mod render_io; | ||
pub mod render_name; | ||
|
||
// Helpers | ||
pub mod render_inject; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use crate::{ | ||
consts::uris::Uris, | ||
utils::domains::Domains, | ||
}; | ||
|
||
pub struct RenderName { | ||
pub domain: String, | ||
pub url_slices: Vec<String>, | ||
} | ||
|
||
impl RenderName { | ||
|
||
pub fn new(url: &str) -> Self { | ||
Self { | ||
domain: Domains::get(url), | ||
url_slices: url.split("/").map(|s| s.to_string()).collect(), | ||
} | ||
} | ||
|
||
fn github_repo_name(&self) -> String { | ||
let segments = &self.url_slices; | ||
let repo_name = &segments[segments.len() - 3]; | ||
repo_name.to_string() | ||
} | ||
|
||
fn gitlab_repo_name(&self) -> String { | ||
let segments = &self.url_slices; | ||
let repo_name = &segments[segments.len() - 5]; | ||
repo_name.to_string() | ||
} | ||
|
||
fn bitbucket_repo_name(&self) -> String { | ||
let segments = &self.url_slices; | ||
let repo_name = &segments[segments.len() - 4]; | ||
repo_name.to_string() | ||
} | ||
|
||
fn codeberg_repo_name(&self) -> String { | ||
let segments = &self.url_slices; | ||
let repo_name = &segments[segments.len() - 5]; | ||
repo_name.to_string() | ||
} | ||
|
||
fn generic(&self) -> String { | ||
if let Some(last_part) = self.url_slices.last() { | ||
last_part.to_string() | ||
} else { | ||
String::new() | ||
} | ||
} | ||
|
||
pub fn get_final_name(&self) -> String { | ||
match &self.domain { | ||
domain if domain == Uris::PROVIDERS_DOMAINS[2] => self.github_repo_name(), | ||
domain if domain == Uris::PROVIDERS_DOMAINS[3] => self.gitlab_repo_name(), | ||
domain if domain == Uris::PROVIDERS_DOMAINS[4] => self.bitbucket_repo_name(), | ||
domain if domain == Uris::PROVIDERS_DOMAINS[5] => self.codeberg_repo_name(), | ||
_ => self.generic(), | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,4 @@ pub mod file; | |
pub mod remote; | ||
pub mod base64; | ||
pub mod domains; | ||
pub mod filename; | ||
pub mod validation; |