Skip to content
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
11 changes: 0 additions & 11 deletions .editorconfig

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
/gems
/auto_generated
.eslintcache
1 change: 0 additions & 1 deletion .husky/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion .husky/pre-commit

This file was deleted.

3 changes: 2 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
engine-strict=true
engine-strict = true
auto-install-peers = false
2 changes: 0 additions & 2 deletions .prettierignore

This file was deleted.

7 changes: 1 addition & 6 deletions .prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
module.exports = {
...require("@discourse/lint-configs/prettier"),
printWidth: 100,
tabWidth: 2,
useTabs: false,
};
module.exports = require("@discourse/lint-configs/prettier");
1 change: 0 additions & 1 deletion .template-lintrc.cjs

This file was deleted.

3 changes: 0 additions & 3 deletions .vscode/extensions.json

This file was deleted.

5 changes: 0 additions & 5 deletions .vscode/settings.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ import Controller from "@ember/controller";
import { action } from "@ember/object";
import { ajax } from "discourse/lib/ajax";

export default class AdminPluginsBBCodeController extends Controller {
@tracked resetEnabled = true;
@tracked success = false;
export default class AdminPluginsShowBbcodeResetController extends Controller {
@tracked error = false;
@tracked isResetting = false;
@tracked success = false;

@action
resetServerJSContext() {
this.resetEnabled = false;
this.isResetting = true;
this.success = false;
this.error = false;
ajax("/BbCode/admin/refresh")

ajax("/BbCode/admin/refresh", { type: "POST" })
.then(() => {
// success
this.resetEnabled = true;
this.success = true;
})
.catch(() => {
// error
this.resetEnabled = true;
this.error = true;
})
.finally(() => {
this.isResetting = false;
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import DPageSubheader from "discourse/ui-kit/d-page-subheader";
import { i18n } from "discourse-i18n";

export default <template>
<div class="admin-detail bbcode-reset">
<DPageSubheader
@descriptionLabel={{i18n "bbcode.resetDesc"}}
@titleLabel={{i18n "bbcode.title"}}
>
<:actions as |actions|>
<actions.Primary
@action={{@controller.resetServerJSContext}}
@icon="arrow-rotate-right"
@isLoading={{@controller.isResetting}}
@label="bbcode.reset"
/>
</:actions>
</DPageSubheader>

{{#if @controller.success}}
<div class="alert alert-success">{{i18n "bbcode.success"}}</div>
{{/if}}

{{#if @controller.error}}
<div class="alert alert-error">{{i18n "bbcode.error"}}</div>
{{/if}}
</div>
</template>
4 changes: 2 additions & 2 deletions app/controllers/bb_code/admin/refresh_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ def index
begin
# Skip warmup in development mode - it makes boot take ~2s longer
PrettyText.cook("warm up **pretty text**")
render json: nil, status: 200
render json: success_json
rescue => e
Rails.logger.error("Failed to warm up pretty text: #{e}")
render json: nil, status: 500
render json: failed_json, status: 500
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @file Initializes any accordion tag with proper js/event handling
*/
import { withPluginApi } from "discourse/lib/plugin-api";
import { apiInitializer } from "discourse/lib/api";

/**
* Adds the inline js for accordion inside a given post
Expand Down Expand Up @@ -175,18 +175,6 @@ class Accordion {
}
}

/**
* The initial called function.
* Any calls to the PluginAPI should be done in here
* @param api
*/
function initializeAccordion(api) {
export default apiInitializer((api) => {
api.decorateCookedElement(addAccordionCode, { id: "add accordions" });
}

export default {
name: "accordion",
initialize() {
withPluginApi("0.11.1", initializeAccordion);
},
};
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { debounce } from "@ember/runloop";
import { apiInitializer } from "discourse/lib/api";
import loadscript from "discourse/lib/load-script";
import { withPluginApi } from "discourse/lib/plugin-api";
/* global bbscriptParser */

/**
Expand Down Expand Up @@ -68,7 +68,9 @@ function addBBScriptLogic(post, isPreview = false) {
let astTree;
if (version === "") {
// unknown version. check for unique () style of bbscript2
version = content.split("\n").some((line) => line.trim().startsWith("(")) ? "2" : "1";
version = content.split("\n").some((line) => line.trim().startsWith("("))
? "2"
: "1";
}
if (version === "2") {
const parsed = bbscriptParser.bbscript2Parser.parse(content);
Expand All @@ -83,7 +85,9 @@ function addBBScriptLogic(post, isPreview = false) {
if (on === "init") {
let target;
if (callerClass) {
target = document.querySelectorAll("." + callerClass + "__" + callerId) || undefined;
target =
document.querySelectorAll("." + callerClass + "__" + callerId) ||
undefined;
}
// only fire when the post is visible
if (!initBBScripts.has(post)) {
Expand Down Expand Up @@ -119,10 +123,17 @@ function addBBScriptLogic(post, isPreview = false) {
*/
const triggerBBScript = (callerId, callerClass, astTree, version, target) => {
if (version === "1") {
bbscriptParser.bbscriptProcessorV1.execAll(astTree, callerId, callerClass, { target });
bbscriptParser.bbscriptProcessorV1.execAll(astTree, callerId, callerClass, {
target,
});
} else if (version === "2") {
try {
bbscriptParser.bbscriptProcessorV2.execAll(astTree, callerId, callerClass, { target });
bbscriptParser.bbscriptProcessorV2.execAll(
astTree,
callerId,
callerClass,
{ target }
);
} catch (e) {
if (e?.message !== "BBScript Stop Command") {
// eslint-disable-next-line no-console
Expand All @@ -132,28 +143,23 @@ const triggerBBScript = (callerId, callerClass, astTree, version, target) => {
}
};

function initializeBBScript(api) {
export default apiInitializer((api) => {
const siteSettings = api.container.lookup("service:site-settings");
if (!siteSettings.enable_bbscript) {
return;
}

api.decorateCookedElement(
(post) => {
loadscript("/plugins/bbcode/javascripts/bbscript-parser.min.js").then(() => {
checkIsPreview(post);
});
loadscript("/plugins/bbcode/javascripts/bbscript-parser.min.js").then(
() => {
checkIsPreview(post);
}
);
},
{
id: "add bbscript",
afterAdopt: true,
}
);
}

export default {
name: "bbscript",
initialize() {
withPluginApi("0.11.1", initializeBBScript);
},
};
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @file Initializes and adds any custom user styles to the post
*/
import { withPluginApi } from "discourse/lib/plugin-api";
import { apiInitializer } from "discourse/lib/api";

/**
* Adds the inline styles for the style tag inside a given post
Expand Down Expand Up @@ -30,13 +30,6 @@ function addClassStyleCode(post) {
});
}

function initializeClassStyle(api) {
export default apiInitializer((api) => {
api.decorateCookedElement(addClassStyleCode, { id: "add class style code" });
}

export default {
name: "class-style",
initialize() {
withPluginApi("0.11.1", initializeClassStyle);
},
};
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { apiInitializer } from "discourse/lib/api";
import loadscript from "discourse/lib/load-script";
import { withPluginApi } from "discourse/lib/plugin-api";

const postsMissingFontAwesome = [];

function initializeFontAwesome(api) {
export default apiInitializer((api) => {
const siteSettings = api.container.lookup("service:site-settings");
if (!siteSettings.fontawesome_kit_url) {
return;
Expand Down Expand Up @@ -59,11 +59,4 @@ function initializeFontAwesome(api) {
// eslint-disable-next-line no-console
console.error("Failed to load Font Awesome Kit", err);
});
}

export default {
name: "bbcode-fontawesome-init",
initialize() {
withPluginApi("0.11.1", initializeFontAwesome);
},
};
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @file Find and adds google fonts to the site when the font bbcode is found with the data-font attribute
*/
import { withPluginApi } from "discourse/lib/plugin-api";
import { apiInitializer } from "discourse/lib/api";

/**
* Adds relevant font links inside a given post
Expand All @@ -20,7 +20,10 @@ function addGoogleFont(post) {
const gFonts = [];
Array.from(elements).map((e) => {
const data = e.getAttribute("data-font");
if (!gFonts.includes(data) && data.startsWith("https://fonts.googleapis.com")) {
if (
!gFonts.includes(data) &&
data.startsWith("https://fonts.googleapis.com")
) {
frag.appendChild(linkBuilder(data));
gFonts.push(data);
}
Expand All @@ -42,20 +45,8 @@ function linkBuilder(data) {
return link;
}

/**
* The initial call function.
* Any calls to the PluginAPI should be done in here
* @param api
*/
function initializeFont(api) {
export default apiInitializer((api) => {
api.decorateCookedElement((elem) => addGoogleFont(elem), {
id: "add google font",
});
}

export default {
name: "google font",
initialize() {
withPluginApi("0.11.1", initializeFont);
},
};
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { withPluginApi } from "discourse/lib/plugin-api";
import { apiInitializer } from "discourse/lib/api";

const NAME_REGEX = /[^\s\]=/"']+/;
const QUOTE_STRING_ALLOW_NL = {
Expand Down Expand Up @@ -84,7 +84,12 @@ function bbcodeHighlight() {
return {
name: "bbcode",
case_insensitive: true,
contains: [CLOSING_TAG, OPENING_TAG_NO_ATTR, OPENING_TAG_SINGLE_ATTR, OPENING_TAG_MULTI_ATTR],
contains: [
CLOSING_TAG,
OPENING_TAG_NO_ATTR,
OPENING_TAG_SINGLE_ATTR,
OPENING_TAG_MULTI_ATTR,
],
};
}

Expand Down Expand Up @@ -334,19 +339,7 @@ function markdownHighlight(hljs) {
};
}

/**
* The initial call function.
* Any calls to the PluginAPI should be done in here
* @param api
*/
function registerHighlightJs(api) {
export default apiInitializer((api) => {
api.registerHighlightJSLanguage("bbcode", bbcodeHighlight);
api.registerHighlightJSLanguage("markdown-bbcode", markdownHighlight);
}

export default {
name: "hightlight-js-bbcode",
initialize() {
withPluginApi("1.4.0", registerHighlightJs);
},
};
});
Loading
Loading