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
2 changes: 2 additions & 0 deletions app/controllers/bb_code/admin/refresh_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ module Admin
class RefreshController < ::Admin::AdminController
requires_plugin PLUGIN_NAME
def index
MessageBus.publish(::BbCode::ENGINE_RESET_CHANNEL, {})

PrettyText.reset_context
begin
# Skip warmup in development mode - it makes boot take ~2s longer
Expand Down
16 changes: 16 additions & 0 deletions assets/javascripts/discourse/api-initializers/engine-reset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { apiInitializer } from "discourse/lib/api";
import { i18n } from "discourse-i18n";

const RESET_CHANNEL = "/bbcode/engine-reset";

export default apiInitializer((api) => {
api.container.lookup("service:message-bus").subscribe(RESET_CHANNEL, () => {
// The markdown-it feature is baked into the app bundle, so a reload is the
// only way to pick it up
api.addGlobalNotice(i18n("bbcode.reload_notice"), "bbcode-engine-reset", {
dismissable: true,
level: "info",
persistentDismiss: false,
});
});
});
3 changes: 2 additions & 1 deletion config/locales/client.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ en:
js:
bbcode:
title: "BBCode"
resetDesc: "The following resets the Markdown-It engine in the backend. This allows the engine to load in the latest code from the custom parser."
resetDesc: "Loads the latest custom parser code into every server process, without a restart. Open browser sessions are shown a banner asking them to refresh, since previews run the parser in the browser."
reload_notice: "The BBCode parser was updated. Refresh the page to use the latest version."
reset: "Reset BBCode Engine"
success: "Successfully reset."
error: "Failed to reset. Please check logs."
6 changes: 6 additions & 0 deletions plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

module ::BbCode
PLUGIN_NAME = "BbCode"

ENGINE_RESET_CHANNEL = "/bbcode/engine-reset"
end

require_relative "lib/bb_code/engine"
Expand All @@ -31,6 +33,10 @@ module ::BbCode
# should clear out the context so the initial setup logic for bbcode parser runs
PrettyText.reset_context()

unless Rails.env.test?
MessageBus.subscribe(::BbCode::ENGINE_RESET_CHANNEL) { PrettyText.reset_context }
end

# overrides the default normalize_whitespaces function in discourse/lib/text_cleaner.rb
# adds discourse_normalize_whitespace setting (defaults to false)
# when true, normalize_whitespace runs as normal
Expand Down
Loading