Skip to content

Commit

Permalink
Add .readable() templater function. TODOs: Docs, Tests for to_reada…
Browse files Browse the repository at this point in the history
…ble, undo to_upper change

At the moment, I don't plan to make it the default, though I might try to do it
if enough people like this.
  • Loading branch information
ilyagr committed Jan 22, 2024
1 parent 71a9143 commit c848a20
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion cli/src/commit_templater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,6 @@ impl Template<()> for ShortestIdPrefix {
// in the alphabet and neither should both `O` and `Q`, etc. See also:
// https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3541865/
// https://www.readnaturally.com/about-us/blog/a-strategy-for-students-who-confuse-letters
#[allow(unused)]
fn to_readable_case(s: &str) -> String {
s.chars()
.map(|c| match c.to_ascii_lowercase() {
Expand All @@ -701,6 +700,13 @@ impl ShortestIdPrefix {
rest: self.rest.to_ascii_uppercase(),
}
}

fn to_readable(&self) -> Self {
Self {
prefix: to_readable_case(&self.prefix),
rest: to_readable_case(&self.rest),
}
}
fn to_lower(&self) -> Self {
Self {
prefix: self.prefix.to_ascii_lowercase(),
Expand Down Expand Up @@ -734,6 +740,12 @@ fn build_shortest_id_prefix_method<'repo>(
language
.wrap_shortest_id_prefix(TemplateFunction::new(self_property, |id| id.to_lower()))
}
"readable" => {
template_parser::expect_no_arguments(function)?;
language.wrap_shortest_id_prefix(TemplateFunction::new(self_property, |id| {
id.to_readable()
}))
}
_ => {
return Err(TemplateParseError::no_such_method(
"ShortestIdPrefix",
Expand Down

0 comments on commit c848a20

Please sign in to comment.