DEV: emoji model should set the group of the emoji (#18237)
We do it for custom emojis but not for standard emojis which is quite unexpected and limit the use cases we can have for it.
This commit is contained in:
parent
56555a0231
commit
09a434e2d8
|
@ -94,6 +94,7 @@ class Emoji
|
|||
e.name = name
|
||||
e.tonable = Emoji.tonable_emojis.include?(name)
|
||||
e.url = Emoji.url_for(filename)
|
||||
e.group = groups[name] || DEFAULT_GROUP
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -122,6 +123,24 @@ class Emoji
|
|||
site_emoji_cache.clear
|
||||
end
|
||||
|
||||
def self.groups_file
|
||||
@groups_file ||= "#{Rails.root}/lib/emoji/groups.json"
|
||||
end
|
||||
|
||||
def self.groups
|
||||
@groups ||= begin
|
||||
groups = {}
|
||||
|
||||
File.open(groups_file, "r:UTF-8") { |f| JSON.parse(f.read) }.each do |group|
|
||||
group["icons"].each do |icon|
|
||||
groups[icon["name"]] = group["name"]
|
||||
end
|
||||
end
|
||||
|
||||
groups
|
||||
end
|
||||
end
|
||||
|
||||
def self.db_file
|
||||
@db_file ||= "#{Rails.root}/lib/emoji/db.json"
|
||||
end
|
||||
|
|
|
@ -136,4 +136,17 @@ RSpec.describe Emoji do
|
|||
expect(replaced_str).to eq("This is a good day <img src=\"/images/emoji/twitter/woman.png?v=#{Emoji::EMOJI_VERSION}\" title=\"woman\" class=\"emoji\" alt=\"woman\" loading=\"lazy\" width=\"20\" height=\"20\"> :foo: :bar:t4: :man:t8:")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".groups" do
|
||||
it "returns an optimized emoji name -> group name datastructure" do
|
||||
expect(Emoji.groups["scotland"]).to eq("flags")
|
||||
end
|
||||
end
|
||||
|
||||
describe "#create_from_db_item" do
|
||||
it "sets the group of the emoji" do
|
||||
emoji = Emoji.create_from_db_item("name" => "scotland")
|
||||
expect(emoji.group).to eq("flags")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue