From 679baf024ce319b0bc13c8fc3cc8c085d19c8af0 Mon Sep 17 00:00:00 2001 From: John Livingston Date: Fri, 22 Sep 2023 13:56:48 +0200 Subject: [PATCH] Moving Mustache templates content in separate files. --- build-client.js | 15 +- client/@types/global.d.ts | 4 + .../configuration/templates/channel.mustache | 185 +++++++++++++++++ .../common/configuration/templates/channel.ts | 192 +----------------- .../configuration/templates/home.mustache | 25 +++ client/common/configuration/templates/home.ts | 28 +-- 6 files changed, 230 insertions(+), 219 deletions(-) create mode 100644 client/common/configuration/templates/channel.mustache create mode 100644 client/common/configuration/templates/home.mustache diff --git a/build-client.js b/build-client.js index bfd22c01..bec8ad7a 100644 --- a/build-client.js +++ b/build-client.js @@ -35,10 +35,23 @@ function loadLocs() { return r } +function loadMustaches () { + // Loading mustache templates, dans filling constants. + const r = [] + r['MUSTACHE_CONFIGURATION_HOME'] = loadMustache('client/common/configuration/templates/home.mustache') + r['MUSTACHE_CONFIGURATION_CHANNEL'] = loadMustache('client/common/configuration/templates/channel.mustache') + return r +} + +function loadMustache (file) { + const filePath = path.resolve(__dirname, file) + return JSON.stringify(fs.readFileSync(filePath).toString()) +} + const define = Object.assign({ PLUGIN_CHAT_PACKAGE_NAME: JSON.stringify(packagejson.name), PLUGIN_CHAT_SHORT_NAME: JSON.stringify(packagejson.name.replace(/^peertube-plugin-/, '')) -}, loadLocs()) +}, loadLocs(), loadMustaches()) const configs = clientFiles.map(f => ({ entryPoints: [ path.resolve(__dirname, 'client', f + '.ts') ], diff --git a/client/@types/global.d.ts b/client/@types/global.d.ts index ed734f6b..6b382490 100644 --- a/client/@types/global.d.ts +++ b/client/@types/global.d.ts @@ -1,6 +1,10 @@ declare const PLUGIN_CHAT_PACKAGE_NAME: string declare const PLUGIN_CHAT_SHORT_NAME: string +// Constants that begins with "MUSTACHE_" are mustache templates, and are built by build-client.js. +declare const MUSTACHE_CONFIGURATION_HOME: string +declare const MUSTACHE_CONFIGURATION_CHANNEL: string + // Constants that begins with "LOC_" are loaded by build-client.js, reading the english locale file. // See the online documentation: https://johnxlivingston.github.io/peertube-plugin-livechat/contributing/translate/ declare const LOC_ONLINE_HELP: string diff --git a/client/common/configuration/templates/channel.mustache b/client/common/configuration/templates/channel.mustache new file mode 100644 index 00000000..341f2731 --- /dev/null +++ b/client/common/configuration/templates/channel.mustache @@ -0,0 +1,185 @@ +
+

+ {{title}}: + + {{channelConfiguration.channel.displayName}} + {{channelConfiguration.channel.name}} + + {{{helpButton}}} +

+

{{description}}

+
+
+
+

{{botOptions}}

+
+
+
+ +
+
+ + +
+
+
+ + {{#forbiddenWordsArray}}{{! iterating on forbiddenWordsArray to display N fields }} +
+
+

{{forbiddenWords}} #{{displayNumber}}

+ {{#displayHelp}} +

{{forbiddenWordsDesc}} {{moreInfo}}

+ {{{HelpButtonForbiddenWords}}} + {{/displayHelp}} +
+
+
+ + {{! warning: don't add extra line break in textarea! }} + +

{{forbiddenWordsDesc2}}

+
+
+ +

{{forbiddenWordsRegexpDesc}}

+
+
+ +

{{forbiddenWordsApplyToModeratorsDesc}}

+
+
+ + +

{{forbiddenWordsReasonDesc}}

+
+
+
+ {{/forbiddenWordsArray}} + + {{#quotesArray}}{{! iterating on quotesArray to display N fields }} +
+
+

{{quoteLabel}} #{{displayNumber}}

+ {{#displayHelp}} +

{{quoteDesc}} {{moreInfo}}

+ {{{helpButtonQuotes}}} + {{/displayHelp}} +
+
+
+ + {{! warning: don't add extra line break in textarea! }} + +

{{quoteDesc2}}

+
+
+ + +

{{quoteDelayDesc}}

+
+
+
+ {{/quotesArray}} + + {{#cmdsArray}}{{! iterating on cmdsArray to display N fields }} +
+
+

{{commandLabel}} #{{displayNumber}}

+ {{#displayHelp}} +

{{commandDesc}} {{moreInfo}}

+ {{{helpButtonCommands}}} + {{/displayHelp}} +
+
+
+ + +

{{commandCmdDesc}}

+
+
+ + +

{{commandMessageDesc}}

+
+
+
+ {{/cmdsArray}} +
+ + +
+
+
diff --git a/client/common/configuration/templates/channel.ts b/client/common/configuration/templates/channel.ts index 474ccbf8..79020065 100644 --- a/client/common/configuration/templates/channel.ts +++ b/client/common/configuration/templates/channel.ts @@ -23,197 +23,7 @@ async function renderConfigurationChannel ( await fillViewHelpButtons(registerClientOptions, view) await fillLabels(registerClientOptions, view) - const content = Mustache.render(` -
-

- {{title}}: - - {{channelConfiguration.channel.displayName}} - {{channelConfiguration.channel.name}} - - {{{helpButton}}} -

-

{{description}}

-
-
-
-

{{botOptions}}

-
-
-
- -
-
- - -
-
-
- - {{#forbiddenWordsArray}}{{! iterating on forbiddenWordsArray to display N fields }} -
-
-

{{forbiddenWords}} #{{displayNumber}}

- {{#displayHelp}} -

{{forbiddenWordsDesc}} {{moreInfo}}

- {{{HelpButtonForbiddenWords}}} - {{/displayHelp}} -
-
-
- - {{! warning: don't add extra line break in textarea! }} - -

{{forbiddenWordsDesc2}}

-
-
- -

{{forbiddenWordsRegexpDesc}}

-
-
- -

{{forbiddenWordsApplyToModeratorsDesc}}

-
-
- - -

{{forbiddenWordsReasonDesc}}

-
-
-
- {{/forbiddenWordsArray}} - - {{#quotesArray}}{{! iterating on quotesArray to display N fields }} -
-
-

{{quoteLabel}} #{{displayNumber}}

- {{#displayHelp}} -

{{quoteDesc}} {{moreInfo}}

- {{{helpButtonQuotes}}} - {{/displayHelp}} -
-
-
- - {{! warning: don't add extra line break in textarea! }} - -

{{quoteDesc2}}

-
-
- - -

{{quoteDelayDesc}}

-
-
-
- {{/quotesArray}} - - {{#cmdsArray}}{{! iterating on cmdsArray to display N fields }} -
-
-

{{commandLabel}} #{{displayNumber}}

- {{#displayHelp}} -

{{commandDesc}} {{moreInfo}}

- {{{helpButtonCommands}}} - {{/displayHelp}} -
-
-
- - -

{{commandCmdDesc}}

-
-
- - -

{{commandMessageDesc}}

-
-
-
- {{/cmdsArray}} -
- - -
-
-
- `, view) as string + const content = Mustache.render(MUSTACHE_CONFIGURATION_CHANNEL, view) as string rootEl.innerHTML = content diff --git a/client/common/configuration/templates/home.mustache b/client/common/configuration/templates/home.mustache new file mode 100644 index 00000000..da0099e8 --- /dev/null +++ b/client/common/configuration/templates/home.mustache @@ -0,0 +1,25 @@ +
+

{{title}}

+

{{description}}

+

{{please_select}}

+ +
diff --git a/client/common/configuration/templates/home.ts b/client/common/configuration/templates/home.ts index 99eaf2b7..fff4e190 100644 --- a/client/common/configuration/templates/home.ts +++ b/client/common/configuration/templates/home.ts @@ -40,33 +40,7 @@ async function renderConfigurationHome (registerClientOptions: RegisterClientOpt channels: channels.data } - return Mustache.render(` -
-

{{title}}

-

{{description}}

-

{{please_select}}

- -
- `, view) as string + return Mustache.render(MUSTACHE_CONFIGURATION_HOME, view) as string } catch (err: any) { peertubeHelpers.notifier.error(err.toString()) return ''