0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00
ghost/test/unit/frontend/helpers
Hannah Wolfe fbc23459fc
Added full SafeString handling to match helper
refs: https://github.com/TryGhost/Team/issues/759

- No matter what, a handlebars helper outputs a string. So if you return true, you'll always get 'true'.
- SafeStrings are handlebars's way of passing around a string whilst also maintaining a record of the original value e.g. new SafeString(true) results in {string: true}
- We need this for the match helper, so that we know when doing a comparison that we're meant to be comparing against a boolean true, not a string true
- Therefore, we need to putput SafeStrings, but also process them when passed in

The logic
- Figuring out the correct logic here has been a little tricky but essentially:
  - {{match safestring}} with a single arg, will return true for any truthy value
  - {{match safestring "=" true}} does a direct comparison with the original value of the safe string, so if it was a boolean true, the match will be true else false
  - {{match (match something) "=" true}} will therefore work for any level of nesting
  - this can result in slightly inconsistent results, but feels correct and documentable

This is documented extensively through the test cases
2021-10-14 16:29:41 +01:00
..
test_tpl
asset.test.js
author.test.js
authors.test.js
body_class.test.js
cancel_link.test.js
concat.test.js
content.test.js
date.test.js
encode.test.js
excerpt.test.js
facebook_url.test.js
foreach.test.js
get.test.js
ghost_foot.test.js
ghost_head.test.js
has.test.js
img_url.test.js
is.test.js
lang.test.js
link.test.js
link_class.test.js
match.test.js Added full SafeString handling to match helper 2021-10-14 16:29:41 +01:00
meta_description.test.js
meta_title.test.js
navigation.test.js
next_post.test.js
page_url.test.js
pagination.test.js
plural.test.js
post_class.test.js
prev_post.test.js
price.test.js
raw.test.js
reading_time.test.js
t.test.js
tags.test.js
title.test.js
twitter_url.test.js
url.test.js