From 075d6b83f4ebe551caa5784df0c7deafbb66ead9 Mon Sep 17 00:00:00 2001 From: Andrei Prigorshnev Date: Wed, 13 Jul 2022 14:54:47 +0400 Subject: [PATCH] DEV: add `emoji` handlebars helper (#17449) --- .../javascripts/discourse/app/helpers/emoji.js | 11 +++++++++++ .../tests/integration/helpers/emoji-test.js | 14 ++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 app/assets/javascripts/discourse/app/helpers/emoji.js create mode 100644 app/assets/javascripts/discourse/tests/integration/helpers/emoji-test.js diff --git a/app/assets/javascripts/discourse/app/helpers/emoji.js b/app/assets/javascripts/discourse/app/helpers/emoji.js new file mode 100644 index 00000000000..54e5f3faa08 --- /dev/null +++ b/app/assets/javascripts/discourse/app/helpers/emoji.js @@ -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); diff --git a/app/assets/javascripts/discourse/tests/integration/helpers/emoji-test.js b/app/assets/javascripts/discourse/tests/integration/helpers/emoji-test.js new file mode 100644 index 00000000000..1378ac0d604 --- /dev/null +++ b/app/assets/javascripts/discourse/tests/integration/helpers/emoji-test.js @@ -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"]`)); + }); +});