Added implicit equals support to match helper

refs: https://github.com/TryGhost/Team/issues/759

- This allows for {{match x y}} to work without having to supply an "=" sign explicitly
This commit is contained in:
Hannah Wolfe 2021-10-14 12:02:50 +01:00
parent fbc23459fc
commit cd765e2393
No known key found for this signature in database
GPG Key ID: 9F8C7532D0A6BA55
2 changed files with 34 additions and 7 deletions

View File

@ -77,9 +77,13 @@ function match(...attrs) {
});
if (attrs.length === 1) {
// If we only have one attribute, treat it as simple true/false (like the if helper)
// CASE: single attribute, treat it as simple true/false (like the if helper)
result = handleConditional(attrs[0], options);
} else if (attrs.length === 2) {
// CASE: two attributes, assume the operator is "="
result = handleMatch(attrs[0], '=', attrs[1]);
} else if (attrs.length === 3) {
// CASE: three attributes, handle the match exactly
result = handleMatch(attrs[0], attrs[1], attrs[2]);
} else {
logging.warn(tpl(messages.invalidAttribute));

View File

@ -100,12 +100,35 @@ describe('Match helper', function () {
});
// @TODO: Implement Implicit Equals
// describe('Implicit Equals', function () {
// runTests({
// '{{match string "Hello world"}}': 'true',
// '{{match string "Hello world!"}}': 'false',
// }, hash);
// });
describe('Implicit Equals', function () {
runTests({
'{{match string "Hello world"}}': 'true',
'{{match string "Hello world!"}}': 'false',
'{{match string_true "true"}}': 'true',
'{{match string_true true}}': 'false',
'{{match string_false "false"}}': 'true',
'{{match string_false false}}': 'false',
'{{match safestring_string_true "true"}}': 'true',
'{{match safestring_string_true true}}': 'false',
'{{match safestring_string_false "false"}}': 'true',
'{{match safestring_string_false false}}': 'false',
'{{match safestring_bool_true "true"}}': 'false',
'{{match safestring_bool_true true}}': 'true',
'{{match safestring_bool_false "false"}}': 'false',
'{{match safestring_bool_false false}}': 'true',
'{{match truthy_bool true}}': 'true',
'{{match truthy_bool false}}': 'false',
'{{match falsy_bool false}}': 'true',
'{{match falsy_bool true}}': 'false',
'{{match one 1}}': 'true',
'{{match one "1"}}': 'false',
'{{match zero 0}}': 'true',
'{{match zero "0"}}': 'false',
'{{match (title) "=" "The Title"}}': 'true',
'{{match (title) "=" "The Title!"}}': 'false'
}, hash);
});
describe('Explicit Equals', function () {
runTests({