DEV: Use named parameters for dir-span helper (#14195)

* DEV: Use named parameters for dir-span helper

Follow up to: e50a5c0c73

In order to improve code clarity this change introduces named parameters
for the dir-span helper. This is specifically for the new `htmlSafe`
parameter which you can use instead of just passing in a boolean if the
strings you are passing in have already been escaped.

Before: `{{dir-span category.description false}}`
After: `{{dir-span category.description htmlSafe=true}}`

* Set default value for params arg
This commit is contained in:
Blake Erickson 2021-08-30 23:51:08 -06:00 committed by GitHub
parent 45a166b6ef
commit a2ccf0a9ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 11 additions and 7 deletions

View File

@ -13,7 +13,11 @@ function setDir(text) {
return content; return content;
} }
export default registerUnbound("dir-span", function (str, escapeText = true) { export default registerUnbound("dir-span", function (str, params = {}) {
let text = escapeText ? escapeExpression(str) : str; let isHtmlSafe = false;
if (params.htmlSafe) {
isHtmlSafe = params.htmlSafe;
}
let text = isHtmlSafe ? str : escapeExpression(str);
return htmlSafe(setDir(text)); return htmlSafe(setDir(text));
}); });

View File

@ -5,7 +5,7 @@
{{category-title-link category=category}} {{category-title-link category=category}}
{{#if category.description_excerpt}} {{#if category.description_excerpt}}
<div class="category-description"> <div class="category-description">
{{dir-span category.description_excerpt false}} {{dir-span category.description_excerpt htmlSafe=true}}
</div> </div>
{{/if}} {{/if}}
{{#if category.isGrandParent}} {{#if category.isGrandParent}}

View File

@ -4,7 +4,7 @@
{{category-title-link tagName="h4" category=category}} {{category-title-link tagName="h4" category=category}}
{{#if category.description_excerpt}} {{#if category.description_excerpt}}
<div class="category-description subcategory-description"> <div class="category-description subcategory-description">
{{dir-span category.description_excerpt false}} {{dir-span category.description_excerpt htmlSafe=true}}
</div> </div>
{{/if}} {{/if}}
{{#if category.subcategories}} {{#if category.subcategories}}

View File

@ -1,6 +1,6 @@
{{#if topic.hasExcerpt}} {{#if topic.hasExcerpt}}
<a href="{{topic.url}}" class="topic-excerpt"> <a href="{{topic.url}}" class="topic-excerpt">
{{dir-span topic.escapedExcerpt false}} {{dir-span topic.escapedExcerpt htmlSafe=true}}
{{#if topic.excerptTruncated}} {{#if topic.excerptTruncated}}
<span class="topic-excerpt-more">{{i18n 'read_more'}}</span> <span class="topic-excerpt-more">{{i18n 'read_more'}}</span>
{{/if}} {{/if}}

View File

@ -11,7 +11,7 @@
}} }}
{{#if category.description}} {{#if category.description}}
<p>{{dir-span category.description false}}</p> <p>{{dir-span category.description htmlSafe=true}}</p>
{{/if}} {{/if}}
{{/if}} {{/if}}

View File

@ -9,7 +9,7 @@
</div> </div>
{{#if shouldDisplayDescription}} {{#if shouldDisplayDescription}}
<div class="category-desc" aria-hidden="true">{{dir-span description false}}</div> <div class="category-desc" aria-hidden="true">{{dir-span description htmlSafe=true}}</div>
{{/if}} {{/if}}
{{else}} {{else}}
{{html-safe label}} {{html-safe label}}