DEV: convert icon name earlier for plugins in test env (#31196)

This makes the backtrace for a deprecated icon name error clearer in
terms of pointing out which plugin the icon is being registered from.
The error will only be raised in the test environment.

This PR also extracts out to a separate module the hashmaps & logic for
converting FA4 era icons to discourse FA6 compatible icons. This
isolates that logic for reuse in DiscoursePluginRegistry - otherwise
pulling in the whole SvgSprite resulted in errors.
This commit is contained in:
Kelv
2025-02-13 07:20:23 +08:00
committed by GitHub
parent 82c7c1dbda
commit 013bf88019
3 changed files with 726 additions and 718 deletions

View File

@ -1,5 +1,5 @@
# frozen_string_literal: true
require_relative "deprecated_icon_handler"
#
# A class that handles interaction between a plugin and the Discourse App.
#
@ -147,6 +147,7 @@ class DiscoursePluginRegistry
end
def self.register_svg_icon(icon)
DeprecatedIconHandler.convert_icon(icon) if Rails.env.test?
self.svg_icons << icon
end
@ -235,6 +236,7 @@ class DiscoursePluginRegistry
"moment.js" => "vendor/assets/javascripts/moment.js",
"moment-timezone.js" => "vendor/assets/javascripts/moment-timezone-with-data.js",
}
def self.core_asset_for_name(name)
asset = VENDORED_CORE_PRETTY_TEXT_MAP[name]
raise KeyError, "Asset #{name} not found in #{VENDORED_CORE_PRETTY_TEXT_MAP}" unless asset