DEV: add `emoji` handlebars helper (#17449)

This commit is contained in:
Andrei Prigorshnev 2022-07-13 14:54:47 +04:00 committed by GitHub
parent f48a1ec648
commit 075d6b83f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 0 deletions

View File

@ -0,0 +1,11 @@
import { emojiUnescape } from "discourse/lib/text";
import { escapeExpression } from "discourse/lib/utilities";
import { htmlSafe } from "@ember/template";
import { helper } from "@ember/component/helper";
function emoji(code, options) {
const escaped = escapeExpression(`:${code}:`);
return htmlSafe(emojiUnescape(escaped, options));
}
export default helper(emoji);

View File

@ -0,0 +1,14 @@
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { render } from "@ember/test-helpers";
import { exists } from "discourse/tests/helpers/qunit-helpers";
import { hbs } from "ember-cli-htmlbars";
module("Integration | Helper | emoji", function (hooks) {
setupRenderingTest(hooks);
test("it renders", async function (assert) {
await render(hbs`{{emoji "tada"}}`);
assert.ok(exists(`.emoji[title="tada"]`));
});
});