1
1
mirror of https://github.com/orhun/git-cliff.git synced 2024-11-29 14:36:25 +03:00

refactor(template): rename capitalize_first filter to upper_first

This commit is contained in:
orhun 2021-06-04 02:30:15 +03:00
parent 0a27f4791e
commit 59f069d890
No known key found for this signature in database
GPG Key ID: B928720AEC532117
2 changed files with 7 additions and 12 deletions

View File

@ -4,11 +4,6 @@
# changelog header
header = """
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
"""
# template for the changelog body
# https://tera.netlify.app/docs/#introduction
@ -19,9 +14,9 @@ body = """
## [unreleased]
{% endif %}\
{% for group, commits in commits | group_by(attribute="group") %}
### {{ group | capitalize_first }}
### {{ group | upper_first }}
{% for commit in commits %}
- {{ commit.message | capitalize_first }}\
- {{ commit.message | upper_first }}\
{% endfor %}
{% endfor %}
"""

View File

@ -19,17 +19,17 @@ impl Template {
pub fn new(template: String) -> Result<Self> {
let mut tera = Tera::default();
tera.add_raw_template("template", &template)?;
tera.register_filter("capitalize_first", Self::capitalize_first_filter);
tera.register_filter("upper_first", Self::upper_first_filter);
Ok(Self { tera })
}
/// Filter for capitalizing the first character of a string.
fn capitalize_first_filter(
/// Filter for making the first character of a string uppercase.
fn upper_first_filter(
value: &Value,
_: &HashMap<String, Value>,
) -> TeraResult<Value> {
let mut s =
tera::try_get_value!("capitalize_first_filter", "value", String, value);
tera::try_get_value!("upper_first_filter", "value", String, value);
let mut c = s.chars();
s = match c.next() {
None => String::new(),
@ -57,7 +57,7 @@ mod test {
## {{ version }}
{% for commit in commits %}
### {{ commit.group }}
- {{ commit.message | capitalize_first }}
- {{ commit.message | upper_first }}
{% endfor %}"#;
let template = Template::new(template.to_string())?;
assert_eq!(