From c919cc8c67d7e05cab11684d8c5d2a0ad54f1f2b Mon Sep 17 00:00:00 2001 From: mStar Date: Fri, 22 Nov 2024 15:55:41 +0100 Subject: [PATCH] Move files around, formatter helper Formatters for username belong to account, not to note New helper for transforming a markdown text to html --- devserver/linstrom.toml | 2 +- .../app/components/note/formatter.hbs | 15 ------------ .../app/components/util/formatter.hbs | 16 +++++++++++++ .../{note => util}/formatter/akoma.hbs | 0 .../{note => util}/formatter/akoma.ts | 0 .../{note => util}/formatter/linstrom.hbs | 0 .../{note => util}/formatter/linstrom.ts | 0 .../{note => util}/formatter/mastodon.hbs | 0 .../{note => util}/formatter/mastodon.ts | 0 .../{note => util}/formatter/misskey.hbs | 0 .../{note => util}/formatter/misskey.ts | 0 .../{note => util}/formatter/wafrn.hbs | 0 .../{note => util}/formatter/wafrn.ts | 0 frontend-reactive/app/helpers/formatter.ts | 24 +++++++++++++++++++ .../components/account/profilepicture-test.ts | 22 ++++++++--------- .../helpers/tokenise-content-test.ts | 17 +++++++++++++ 16 files changed, 69 insertions(+), 27 deletions(-) delete mode 100644 frontend-reactive/app/components/note/formatter.hbs create mode 100644 frontend-reactive/app/components/util/formatter.hbs rename frontend-reactive/app/components/{note => util}/formatter/akoma.hbs (100%) rename frontend-reactive/app/components/{note => util}/formatter/akoma.ts (100%) rename frontend-reactive/app/components/{note => util}/formatter/linstrom.hbs (100%) rename frontend-reactive/app/components/{note => util}/formatter/linstrom.ts (100%) rename frontend-reactive/app/components/{note => util}/formatter/mastodon.hbs (100%) rename frontend-reactive/app/components/{note => util}/formatter/mastodon.ts (100%) rename frontend-reactive/app/components/{note => util}/formatter/misskey.hbs (100%) rename frontend-reactive/app/components/{note => util}/formatter/misskey.ts (100%) rename frontend-reactive/app/components/{note => util}/formatter/wafrn.hbs (100%) rename frontend-reactive/app/components/{note => util}/formatter/wafrn.ts (100%) create mode 100644 frontend-reactive/app/helpers/formatter.ts create mode 100644 frontend-reactive/tests/integration/helpers/tokenise-content-test.ts diff --git a/devserver/linstrom.toml b/devserver/linstrom.toml index 0b6ccee..a35cb47 100644 --- a/devserver/linstrom.toml +++ b/devserver/linstrom.toml @@ -9,7 +9,7 @@ [admin] username = "server-admin" first_time_setup_otp = "Example otp password" - profiling_password = "Example profiling password" + profiling_password = "" [webauthn] display_name = "Linstrom" diff --git a/frontend-reactive/app/components/note/formatter.hbs b/frontend-reactive/app/components/note/formatter.hbs deleted file mode 100644 index f65a5de..0000000 --- a/frontend-reactive/app/components/note/formatter.hbs +++ /dev/null @@ -1,15 +0,0 @@ -
-{{#if (equals @server "mastodon")}} -{{ @content }}Masto -{{else if (equals @server "misskey")}} - {{ @content }}Misskey -{{else if (equals @server "akoma")}} - {{ @content }}Akoma -{{else if (equals @server "linstrom")}} - {{ @content }}Linstrom -{{else if (equals @server "wafrn")}} - {{ @content }}Wafrn -{{else}} - {{ @content }}Unkown:{{@server}} -{{/if}} -
diff --git a/frontend-reactive/app/components/util/formatter.hbs b/frontend-reactive/app/components/util/formatter.hbs new file mode 100644 index 0000000..80e3492 --- /dev/null +++ b/frontend-reactive/app/components/util/formatter.hbs @@ -0,0 +1,16 @@ +
+ {{#if (equals @server "mastodon")}} + {{@content}}Masto + {{else if (equals @server "misskey")}} + {{@content}}Misskey + {{else if (equals @server "akoma")}} + {{@content}}Akoma + {{else if (equals @server "linstrom")}} + {{@content}}Linstrom + {{else if (equals @server "wafrn")}} + {{@content}}Wafrn + {{else}} + {{@content}}Unkown:{{@server}} + {{/if}} +
\ No newline at end of file diff --git a/frontend-reactive/app/components/note/formatter/akoma.hbs b/frontend-reactive/app/components/util/formatter/akoma.hbs similarity index 100% rename from frontend-reactive/app/components/note/formatter/akoma.hbs rename to frontend-reactive/app/components/util/formatter/akoma.hbs diff --git a/frontend-reactive/app/components/note/formatter/akoma.ts b/frontend-reactive/app/components/util/formatter/akoma.ts similarity index 100% rename from frontend-reactive/app/components/note/formatter/akoma.ts rename to frontend-reactive/app/components/util/formatter/akoma.ts diff --git a/frontend-reactive/app/components/note/formatter/linstrom.hbs b/frontend-reactive/app/components/util/formatter/linstrom.hbs similarity index 100% rename from frontend-reactive/app/components/note/formatter/linstrom.hbs rename to frontend-reactive/app/components/util/formatter/linstrom.hbs diff --git a/frontend-reactive/app/components/note/formatter/linstrom.ts b/frontend-reactive/app/components/util/formatter/linstrom.ts similarity index 100% rename from frontend-reactive/app/components/note/formatter/linstrom.ts rename to frontend-reactive/app/components/util/formatter/linstrom.ts diff --git a/frontend-reactive/app/components/note/formatter/mastodon.hbs b/frontend-reactive/app/components/util/formatter/mastodon.hbs similarity index 100% rename from frontend-reactive/app/components/note/formatter/mastodon.hbs rename to frontend-reactive/app/components/util/formatter/mastodon.hbs diff --git a/frontend-reactive/app/components/note/formatter/mastodon.ts b/frontend-reactive/app/components/util/formatter/mastodon.ts similarity index 100% rename from frontend-reactive/app/components/note/formatter/mastodon.ts rename to frontend-reactive/app/components/util/formatter/mastodon.ts diff --git a/frontend-reactive/app/components/note/formatter/misskey.hbs b/frontend-reactive/app/components/util/formatter/misskey.hbs similarity index 100% rename from frontend-reactive/app/components/note/formatter/misskey.hbs rename to frontend-reactive/app/components/util/formatter/misskey.hbs diff --git a/frontend-reactive/app/components/note/formatter/misskey.ts b/frontend-reactive/app/components/util/formatter/misskey.ts similarity index 100% rename from frontend-reactive/app/components/note/formatter/misskey.ts rename to frontend-reactive/app/components/util/formatter/misskey.ts diff --git a/frontend-reactive/app/components/note/formatter/wafrn.hbs b/frontend-reactive/app/components/util/formatter/wafrn.hbs similarity index 100% rename from frontend-reactive/app/components/note/formatter/wafrn.hbs rename to frontend-reactive/app/components/util/formatter/wafrn.hbs diff --git a/frontend-reactive/app/components/note/formatter/wafrn.ts b/frontend-reactive/app/components/util/formatter/wafrn.ts similarity index 100% rename from frontend-reactive/app/components/note/formatter/wafrn.ts rename to frontend-reactive/app/components/util/formatter/wafrn.ts diff --git a/frontend-reactive/app/helpers/formatter.ts b/frontend-reactive/app/helpers/formatter.ts new file mode 100644 index 0000000..8e3f7ee --- /dev/null +++ b/frontend-reactive/app/helpers/formatter.ts @@ -0,0 +1,24 @@ +import { helper } from '@ember/component/helper' + +class Token { + declare token: string + declare elements: Array + + public constructor(token: string) { + this.token = token + this.elements = new Array() + } +} + +export default helper(function formatter( + positional: Array, + named: { + matchers: Array<{ match: RegExp; replace: string }> + }, +): string { + let out = positional[0] ?? '' + named.matchers.forEach((x) => { + out = out.replaceAll(x.match, x.replace) + }) + return out +}) diff --git a/frontend-reactive/tests/integration/components/account/profilepicture-test.ts b/frontend-reactive/tests/integration/components/account/profilepicture-test.ts index 76d1734..fda6bf9 100644 --- a/frontend-reactive/tests/integration/components/account/profilepicture-test.ts +++ b/frontend-reactive/tests/integration/components/account/profilepicture-test.ts @@ -1,26 +1,26 @@ -import { module, test } from 'qunit' -import { setupRenderingTest } from 'frontend-reactive/tests/helpers' -import { render } from '@ember/test-helpers' -import { hbs } from 'ember-cli-htmlbars' +import { module, test } from 'qunit'; +import { setupRenderingTest } from 'frontend-reactive/tests/helpers'; +import { render } from '@ember/test-helpers'; +import { hbs } from 'ember-cli-htmlbars'; module('Integration | Component | account/profilepicture', function (hooks) { - setupRenderingTest(hooks) + setupRenderingTest(hooks); test('it renders', async function (assert) { // Set any properties with this.set('myProperty', 'value'); // Handle any actions with this.set('myAction', function(val) { ... }); - await render(hbs``) + await render(hbs``); - assert.dom().hasText('') + assert.dom().hasText(''); // Template block usage: await render(hbs` template block text - `) + `); - assert.dom().hasText('template block text') - }) -}) + assert.dom().hasText('template block text'); + }); +}); diff --git a/frontend-reactive/tests/integration/helpers/tokenise-content-test.ts b/frontend-reactive/tests/integration/helpers/tokenise-content-test.ts new file mode 100644 index 0000000..d24e3ec --- /dev/null +++ b/frontend-reactive/tests/integration/helpers/tokenise-content-test.ts @@ -0,0 +1,17 @@ +import { module, test } from 'qunit' +import { setupRenderingTest } from 'frontend-reactive/tests/helpers' +import { render } from '@ember/test-helpers' +import { hbs } from 'ember-cli-htmlbars' + +module('Integration | Helper | tokeniseContent', function (hooks) { + setupRenderingTest(hooks) + + // TODO: Replace this with your real tests. + test('it renders', async function (assert) { + this.set('inputValue', '1234') + + await render(hbs`{{formatter this.inputValue}}`) + + assert.dom().hasText('1234') + }) +})