mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 05:37:34 +03:00
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:
parent
fbc23459fc
commit
cd765e2393
@ -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));
|
||||
|
@ -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({
|
||||
|
Loading…
Reference in New Issue
Block a user