Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEV: Remove Handlebars dependency #299

Merged
merged 1 commit into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions assets/javascripts/discourse/components/custom-user-selector.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { isEmpty } from "@ember/utils";
import Handlebars from "handlebars";
import $ from "jquery";
import TextField from "discourse/components/text-field";
import { renderAvatar } from "discourse/helpers/user-avatar";
import { default as computed, observes } from "discourse/lib/decorators";
import userSearch from "discourse/lib/user-search";
import {
default as computed,
observes,
} from "discourse-common/utils/decorators";
import I18n from "I18n";
import { escapeExpression } from "discourse/lib/utilities";
import { i18n } from "discourse-i18n";

const template = function (params) {
const options = params.options;
Expand All @@ -17,11 +14,11 @@ const template = function (params) {
if (options.users) {
html += "<ul>";
options.users.forEach((u) => {
html += `<li><a href title="${u.name}">`;
html += `<li><a href title="${escapeExpression(u.name)}">`;
html += renderAvatar(u, { imageSize: "tiny" });
html += `<span class='username'>${u.username}</span>`;
html += `<span class='username'>${escapeExpression(u.username)}</span>`;
if (u.name) {
html += `<span class='name'>${u.name}</span>`;
html += `<span class='name'>${escapeExpression(u.name)}</span>`;
}
html += `</a></li>`;
});
Expand All @@ -30,7 +27,7 @@ const template = function (params) {

html += "</div>";

return new Handlebars.SafeString(html).string;
return html;
};

export default TextField.extend({
Expand All @@ -42,7 +39,7 @@ export default TextField.extend({

@computed("placeholderKey")
placeholder(placeholderKey) {
return placeholderKey ? I18n.t(placeholderKey) : "";
return placeholderKey ? i18n(placeholderKey) : "";
},

@observes("usernames")
Expand Down
10 changes: 5 additions & 5 deletions assets/javascripts/discourse/helpers/wizard-char-counter.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import Handlebars from "handlebars";
import I18n from "I18n";
import { htmlSafe } from "@ember/template";
import { i18n } from "discourse-i18n";

export default function wizardCharCounter(body, maxLength) {
let bodyLength = body ? body.length : 0;
let finalString;

if (maxLength) {
let isOverMax = bodyLength > maxLength ? "true" : "false";
finalString = `<div class="body-length" data-length=${bodyLength} data-over-max=${isOverMax}>${bodyLength} / ${I18n.t(
finalString = `<div class="body-length" data-length=${bodyLength} data-over-max=${isOverMax}>${bodyLength} / ${i18n(
"wizard.x_characters",
{ count: parseInt(maxLength, 10) }
)}</div>`;
} else {
finalString = `<div class="body-length">${I18n.t("wizard.x_characters", {
finalString = `<div class="body-length">${i18n("wizard.x_characters", {
count: parseInt(bodyLength, 10),
})}</div>`;
}

return new Handlebars.SafeString(finalString);
return htmlSafe(finalString);
}
Loading