From b94e192a8652daf8ef47f07041ba93273b5fd2b0 Mon Sep 17 00:00:00 2001
From: Alexander Meindl
Date: Mon, 5 Aug 2024 20:20:45 +0200
Subject: [PATCH] drop fall back emoji support and add routing helper class
---
app/models/additionals_router.rb | 9 +++++++
config/settings.yml | 1 -
lib/additionals.rb | 9 -------
lib/additionals/formatter.rb | 19 --------------
lib/additionals/gemify.rb | 22 ----------------
.../common_mark/emoji_filter.rb | 2 +-
test/test_helper.rb | 4 +++
test/unit/additionals_router_test.rb | 25 +++++++++++++++++++
test/unit/wiki_formating/common_mark_test.rb | 5 ++--
test/unit/wiki_formating/markdown_test.rb | 15 ++++-------
test/unit/wiki_formating/textile_test.rb | 15 ++++-------
11 files changed, 51 insertions(+), 75 deletions(-)
create mode 100644 app/models/additionals_router.rb
create mode 100644 test/unit/additionals_router_test.rb
diff --git a/app/models/additionals_router.rb b/app/models/additionals_router.rb
new file mode 100644
index 00000000..83fb54f1
--- /dev/null
+++ b/app/models/additionals_router.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class AdditionalsRouter
+ include Rails.application.routes.url_helpers
+
+ def self.default_url_options
+ ::Mailer.default_url_options
+ end
+end
diff --git a/config/settings.yml b/config/settings.yml
index 173e868c..05f084c0 100644
--- a/config/settings.yml
+++ b/config/settings.yml
@@ -3,7 +3,6 @@ account_login_bottom: ''
add_go_to_top: 0
disabled_modules:
emoji_support: 0
-disable_emoji_native_support: 0
global_footer: ''
global_sidebar: ''
global_wiki_sidebar: ''
diff --git a/lib/additionals.rb b/lib/additionals.rb
index 680857c1..e95d9069 100644
--- a/lib/additionals.rb
+++ b/lib/additionals.rb
@@ -7,15 +7,10 @@ module Additionals
DEFAULT_MODAL_WIDTH = '350px'
GOTO_LIST = " \xc2\xbb"
LIST_SEPARATOR = "#{GOTO_LIST} ".freeze
- EMOJI_ASSERT_PATH = 'plugin_assets/additionals/images/emojis'
include RedminePluginKit::PluginBase
class << self
- def full_url(path = nil)
- "#{Setting.protocol}://#{Setting.host_name.chomp '/'}#{path}"
- end
-
def class_prefix(klass)
klass_name = klass.is_a?(String) ? klass : klass.name
klass_name.underscore.tr '/', '_'
@@ -174,10 +169,6 @@ module Additionals
# create some side effencts
plugin_id = 'additionals'
- # TODO: enable again, if fallback for emoji support
- # has been implemented for mail delivery and pdf
- # Additionals::Gemify.install_emoji_assets
-
# if plugin is already in plugins directory, use this and leave here
next if Redmine::Plugin.installed? plugin_id
diff --git a/lib/additionals/formatter.rb b/lib/additionals/formatter.rb
index fb846b89..919ff69b 100644
--- a/lib/additionals/formatter.rb
+++ b/lib/additionals/formatter.rb
@@ -50,14 +50,6 @@ module Additionals
end
def emoji_tag(emoji, _emoji_code)
- if Additionals.setting? :disable_emoji_native_support
- emoji_tag_fallback emoji
- else
- emoji_tag_native emoji
- end
- end
-
- def emoji_tag_native(emoji)
return unless emoji
data = {
@@ -69,17 +61,6 @@ module Additionals
ActionController::Base.helpers.content_tag 'additionals-emoji', emoji.codepoints, options
end
- def emoji_tag_fallback(emoji)
- ActionController::Base.helpers.image_tag emoji_image_path(emoji),
- title: emoji.description,
- class: 'inline_emojify'
- end
-
- def emoji_image_path(emoji, local: false)
- base_url = local ? '/' : Additionals.full_url
- File.join base_url, Additionals::EMOJI_ASSERT_PATH, emoji.image_name
- end
-
def with_emoji?(text)
text.match? emoji_pattern
end
diff --git a/lib/additionals/gemify.rb b/lib/additionals/gemify.rb
index 371b067a..3c518646 100644
--- a/lib/additionals/gemify.rb
+++ b/lib/additionals/gemify.rb
@@ -3,28 +3,6 @@
module Additionals
class Gemify
class << self
- # install emoji fallback assets from gem (without asset pipeline)
- def install_emoji_assets
- Additionals.debug 'install_emoji_assets'
- return Rails.logger.error 'TanukiEmoji class for emoji not found' unless defined? TanukiEmoji
-
- source_image_path = TanukiEmoji.images_path
- target_image_path = File.join Dir.pwd, 'public', Additionals::EMOJI_ASSERT_PATH
-
- begin
- FileUtils.mkdir_p target_image_path
- rescue StandardError => e
- raise "Could not create directory #{target_image_path}: " + e.message
- end
-
- Dir["#{source_image_path}/*"].each do |file|
- target = File.join target_image_path, file.gsub(source_image_path, '')
- FileUtils.cp file, target unless File.exist?(target) && FileUtils.identical?(file, target)
- rescue StandardError => e
- raise "Could not copy #{file} to #{target}: " + e.message
- end
- end
-
# install assets from gem (without asset pipline)
def install_assets(plugin_id = 'additionals')
return unless Gem.loaded_specs[plugin_id]
diff --git a/lib/additionals/wiki_formatting/common_mark/emoji_filter.rb b/lib/additionals/wiki_formatting/common_mark/emoji_filter.rb
index 9d36ae99..ba2c6b1a 100644
--- a/lib/additionals/wiki_formatting/common_mark/emoji_filter.rb
+++ b/lib/additionals/wiki_formatting/common_mark/emoji_filter.rb
@@ -45,7 +45,7 @@ module Additionals
def emoji_unicode_element_unicode_filter(text)
text.gsub emoji_unicode_pattern do |moji|
emoji = TanukiEmoji.find_by_codepoints moji # rubocop: disable Rails/DynamicFindBy
- emoji_tag_native emoji
+ emoji_tag emoji
end
end
diff --git a/test/test_helper.rb b/test/test_helper.rb
index 0d37eb1e..73cfd547 100755
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -36,6 +36,10 @@ module Additionals
EnabledModule.create project: project, name: 'issue_tracking'
end
end
+
+ def emoji_heart_tag
+ '❤'
+ end
end
module PluginFixturesLoader
diff --git a/test/unit/additionals_router_test.rb b/test/unit/additionals_router_test.rb
new file mode 100644
index 00000000..89800354
--- /dev/null
+++ b/test/unit/additionals_router_test.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+require File.expand_path '../../test_helper', __FILE__
+
+class AdditionalsRouterTest < Additionals::TestCase
+ include Redmine::I18n
+
+ def test_url_for
+ router = AdditionalsRouter.new
+
+ assert_equal 'http://localhost:3000/', router.url_for(:home)
+ end
+
+ def test_routing_url
+ router = AdditionalsRouter.new
+
+ assert_equal 'http://localhost:3000/projects/1', router.project_url(1)
+ end
+
+ def test_routing_path
+ router = AdditionalsRouter.new
+
+ assert_equal '/projects/1', router.project_path(1)
+ end
+end
diff --git a/test/unit/wiki_formating/common_mark_test.rb b/test/unit/wiki_formating/common_mark_test.rb
index d1463e5b..05692733 100644
--- a/test/unit/wiki_formating/common_mark_test.rb
+++ b/test/unit/wiki_formating/common_mark_test.rb
@@ -33,7 +33,7 @@ module WikiFormatting
HTML
expected = <<~HTML
-
+ #{emoji_heart_tag}
def foo
:heart:
@@ -42,8 +42,7 @@ module WikiFormatting
HTML
with_plugin_settings 'additionals', legacy_smiley_support: 0,
- emoji_support: 1,
- disable_emoji_native_support: 1 do
+ emoji_support: 1 do
assert_equal expected, emoji_filter(input)
end
end
diff --git a/test/unit/wiki_formating/markdown_test.rb b/test/unit/wiki_formating/markdown_test.rb
index 26fe4afa..728347fe 100644
--- a/test/unit/wiki_formating/markdown_test.rb
+++ b/test/unit/wiki_formating/markdown_test.rb
@@ -24,32 +24,27 @@ module WikiFormatting
def test_emojies
with_plugin_settings 'additionals', legacy_smiley_support: 0,
- emoji_support: 1,
- disable_emoji_native_support: 1 do
+ emoji_support: 1 do
text = 'A test with a :heart: emoji'
- assert_equal 'A test with a emoji
",
+ assert_equal "A test with a #{emoji_heart_tag} emoji
",
@formatter.new(text).to_html.strip
end
end
def test_smilies_and_emojies
with_plugin_settings 'additionals', legacy_smiley_support: 1,
- emoji_support: 1,
- disable_emoji_native_support: 1 do
+ emoji_support: 1 do
text = ':heart: and :)'
- assert_equal '" \
+ assert_equal "
#{emoji_heart_tag}" \
' and
',
@formatter.new(text).to_html.strip
text = ' :) and :heart:'
assert_equal ' and' \
- '
",
+ " #{emoji_heart_tag}
",
@formatter.new(text).to_html.strip
end
end
diff --git a/test/unit/wiki_formating/textile_test.rb b/test/unit/wiki_formating/textile_test.rb
index a73035e7..508c1b73 100644
--- a/test/unit/wiki_formating/textile_test.rb
+++ b/test/unit/wiki_formating/textile_test.rb
@@ -28,13 +28,11 @@ module WikiFormatting
def test_emojies
with_plugin_settings 'additionals', legacy_smiley_support: 0,
- emoji_support: 1,
- disable_emoji_native_support: 1 do
+ emoji_support: 1 do
@formatter::RULES.delete :inline_smileys
str = 'A test with a :heart: emoji and a :) smiley'
- @to_test[str] = 'A test with a emoji and a :) smiley"
+ @to_test[str] = "A test with a #{emoji_heart_tag} emoji and a :) smiley"
assert_html_output @to_test
end
@@ -42,17 +40,14 @@ module WikiFormatting
def test_smilies_and_emojies
with_plugin_settings 'additionals', legacy_smiley_support: 1,
- emoji_support: 1,
- disable_emoji_native_support: 1 do
+ emoji_support: 1 do
# this is required, because inline_smileys are activated with controller action
@formatter::RULES << :inline_smileys
- @to_test[':heart: and :)'] = '" \
+ @to_test[':heart: and :)'] = "#{emoji_heart_tag}" \
' and '
@to_test[':) and :heart:'] = ' and' \
- ' "
+ " #{emoji_heart_tag}"
assert_html_output @to_test
end