-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
templates: add .email_domain() method to signatures TODO: test
This is slightly less pretty than making an Email type, but I think is much easier. I would use instead of the last argument of: ``` concat( label("email", signature.username()), "@", label("email", signature.email().remove_prefix( signature.username() ++ "@" ) ) ) ```
- Loading branch information
Showing
2 changed files
with
21 additions
and
0 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 |
---|---|---|
|
@@ -787,6 +787,17 @@ fn builtin_signature_methods<'a, L: TemplateLanguage<'a> + ?Sized>( | |
Ok(L::wrap_string(out_property)) | ||
}, | ||
); | ||
map.insert( | ||
"email_domain", | ||
|_language, _diagnostics, _build_ctx, self_property, function| { | ||
function.expect_no_arguments()?; | ||
let out_property = self_property.map(|signature| { | ||
let (_, domain) = text_util::split_email(&signature.email); | ||
domain.unwrap_or_default().to_owned() | ||
}); | ||
Ok(L::wrap_string(out_property)) | ||
}, | ||
); | ||
map.insert( | ||
"timestamp", | ||
|_language, _diagnostics, _build_ctx, self_property, function| { | ||
|
@@ -2156,6 +2167,7 @@ mod tests { | |
insta::assert_snapshot!(env.render_ok(r#"author.name()"#), @"Test User"); | ||
insta::assert_snapshot!(env.render_ok(r#"author.email()"#), @"[email protected]"); | ||
insta::assert_snapshot!(env.render_ok(r#"author.username()"#), @"test.user"); | ||
insta::assert_snapshot!(env.render_ok(r#"author.email_domain()"#), @"example.com"); | ||
|
||
env.add_keyword("author", || { | ||
L::wrap_signature(Literal(new_signature( | ||
|
@@ -2167,6 +2179,7 @@ mod tests { | |
insta::assert_snapshot!(env.render_ok(r#"author.name()"#), @"Another Test User"); | ||
insta::assert_snapshot!(env.render_ok(r#"author.email()"#), @"[email protected]"); | ||
insta::assert_snapshot!(env.render_ok(r#"author.username()"#), @"test.user"); | ||
insta::assert_snapshot!(env.render_ok(r#"author.email_domain()"#), @"example.com"); | ||
|
||
env.add_keyword("author", || { | ||
L::wrap_signature(Literal(new_signature( | ||
|
@@ -2178,13 +2191,15 @@ mod tests { | |
insta::assert_snapshot!(env.render_ok(r#"author.name()"#), @"Test User"); | ||
insta::assert_snapshot!(env.render_ok(r#"author.email()"#), @"test.user@[email protected]"); | ||
insta::assert_snapshot!(env.render_ok(r#"author.username()"#), @"test.user"); | ||
insta::assert_snapshot!(env.render_ok(r#"author.email_domain()"#), @"[email protected]"); | ||
|
||
env.add_keyword("author", || { | ||
L::wrap_signature(Literal(new_signature("Test User", "test.user"))) | ||
}); | ||
insta::assert_snapshot!(env.render_ok(r#"author"#), @"Test User <test.user>"); | ||
insta::assert_snapshot!(env.render_ok(r#"author.email()"#), @"test.user"); | ||
insta::assert_snapshot!(env.render_ok(r#"author.username()"#), @"test.user"); | ||
insta::assert_snapshot!(env.render_ok(r#"author.email_domain()"#), @""); | ||
|
||
env.add_keyword("author", || { | ||
L::wrap_signature(Literal(new_signature( | ||
|
@@ -2195,13 +2210,15 @@ mod tests { | |
insta::assert_snapshot!(env.render_ok(r#"author"#), @"Test User <[email protected]>"); | ||
insta::assert_snapshot!(env.render_ok(r#"author.email()"#), @"[email protected]"); | ||
insta::assert_snapshot!(env.render_ok(r#"author.username()"#), @"test.user+tag"); | ||
insta::assert_snapshot!(env.render_ok(r#"author.email_domain()"#), @"example.com"); | ||
|
||
env.add_keyword("author", || { | ||
L::wrap_signature(Literal(new_signature("Test User", "x@y"))) | ||
}); | ||
insta::assert_snapshot!(env.render_ok(r#"author"#), @"Test User <x@y>"); | ||
insta::assert_snapshot!(env.render_ok(r#"author.email()"#), @"x@y"); | ||
insta::assert_snapshot!(env.render_ok(r#"author.username()"#), @"x"); | ||
insta::assert_snapshot!(env.render_ok(r#"author.email_domain()"#), @"y"); | ||
|
||
env.add_keyword("author", || { | ||
L::wrap_signature(Literal(new_signature("", "[email protected]"))) | ||
|
@@ -2210,6 +2227,7 @@ mod tests { | |
insta::assert_snapshot!(env.render_ok(r#"author.name()"#), @""); | ||
insta::assert_snapshot!(env.render_ok(r#"author.email()"#), @"[email protected]"); | ||
insta::assert_snapshot!(env.render_ok(r#"author.username()"#), @"test.user"); | ||
insta::assert_snapshot!(env.render_ok(r#"author.email_domain()"#), @"example.com"); | ||
|
||
env.add_keyword("author", || { | ||
L::wrap_signature(Literal(new_signature("Test User", ""))) | ||
|
@@ -2218,6 +2236,7 @@ mod tests { | |
insta::assert_snapshot!(env.render_ok(r#"author.name()"#), @"Test User"); | ||
insta::assert_snapshot!(env.render_ok(r#"author.email()"#), @""); | ||
insta::assert_snapshot!(env.render_ok(r#"author.username()"#), @""); | ||
insta::assert_snapshot!(env.render_ok(r#"author.email_domain()"#), @""); | ||
|
||
env.add_keyword("author", || { | ||
L::wrap_signature(Literal(new_signature("", ""))) | ||
|
@@ -2226,6 +2245,7 @@ mod tests { | |
insta::assert_snapshot!(env.render_ok(r#"author.name()"#), @""); | ||
insta::assert_snapshot!(env.render_ok(r#"author.email()"#), @""); | ||
insta::assert_snapshot!(env.render_ok(r#"author.username()"#), @""); | ||
insta::assert_snapshot!(env.render_ok(r#"author.email_domain()"#), @""); | ||
} | ||
|
||
#[test] | ||
|
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