mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 16:21:18 +08:00
FIX: Plugin Custom emoji weren't working correctly on the server side
This commit is contained in:
@ -3,6 +3,21 @@ require 'fileutils'
|
||||
require_dependency 'plugin/metadata'
|
||||
require_dependency 'plugin/auth_provider'
|
||||
|
||||
class Plugin::CustomEmoji
|
||||
def self.cache_key
|
||||
@@cache_key ||= "plugin-emoji"
|
||||
end
|
||||
|
||||
def self.emojis
|
||||
@@emojis ||= {}
|
||||
end
|
||||
|
||||
def self.register(name, url)
|
||||
@@cache_key = Digest::SHA1.hexdigest(cache_key + name)[0..10]
|
||||
emojis[name] = url
|
||||
end
|
||||
end
|
||||
|
||||
class Plugin::Instance
|
||||
|
||||
attr_accessor :path, :metadata
|
||||
@ -17,13 +32,8 @@ class Plugin::Instance
|
||||
}
|
||||
end
|
||||
|
||||
# Memoized hash readers
|
||||
[:seed_data, :emojis].each do |att|
|
||||
class_eval %Q{
|
||||
def #{att}
|
||||
@#{att} ||= HashWithIndifferentAccess.new({})
|
||||
end
|
||||
}
|
||||
def seed_data
|
||||
@seed_data ||= HashWithIndifferentAccess.new({})
|
||||
end
|
||||
|
||||
def self.find_all(parent_path)
|
||||
@ -225,7 +235,7 @@ class Plugin::Instance
|
||||
end
|
||||
|
||||
def register_emoji(name, url)
|
||||
emojis[name] = url
|
||||
Plugin::CustomEmoji.register(name, url)
|
||||
end
|
||||
|
||||
def automatic_assets
|
||||
@ -264,29 +274,6 @@ JS
|
||||
end
|
||||
end
|
||||
|
||||
if emojis.present?
|
||||
emoji_registrations = ""
|
||||
emojis.each do |name, url|
|
||||
emoji_registrations << "emoji.registerEmoji(#{name.inspect}, #{url.inspect});\n"
|
||||
end
|
||||
|
||||
js << <<~JS
|
||||
define("discourse/initializers/custom-emoji",
|
||||
["pretty-text/emoji", "exports"],
|
||||
function(emoji, __exports__) {
|
||||
"use strict";
|
||||
|
||||
__exports__["default"] = {
|
||||
name: "custom-emoji",
|
||||
after: "inject-objects",
|
||||
initialize: function(container) {
|
||||
#{emoji_registrations}
|
||||
}
|
||||
};
|
||||
});
|
||||
JS
|
||||
end
|
||||
|
||||
# Generate an IIFE for the JS
|
||||
js = "(function(){#{js}})();" if js.present?
|
||||
|
||||
|
Reference in New Issue
Block a user