diff options
author | Claire <claire.github-309c@sitedethib.com> | 2022-05-11 09:37:48 +0200 |
---|---|---|
committer | Claire <claire.github-309c@sitedethib.com> | 2022-05-11 09:37:48 +0200 |
commit | 5fd8780b1429acd2bea908695e13c41375d189d7 (patch) | |
tree | c870d368c2a9d0bfd2176057c0b99dad48338248 /app/lib/emoji_formatter.rb | |
parent | e8b8ac8908c6623f0fd7ffccc7de3882a773b72f (diff) | |
parent | 95555f15b55291b97477465f8d8a7eba526d6522 (diff) |
Merge branch 'main' into glitch-soc/merge-upstream
Conflicts: - `package.json`: Not really a conflict, upstream updated a dependency textually adjacent to a glitch-soc-only one. Updated the dependency as upstream did.
Diffstat (limited to 'app/lib/emoji_formatter.rb')
-rw-r--r-- | app/lib/emoji_formatter.rb | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/app/lib/emoji_formatter.rb b/app/lib/emoji_formatter.rb index f808f3a22..194849c23 100644 --- a/app/lib/emoji_formatter.rb +++ b/app/lib/emoji_formatter.rb @@ -11,6 +11,7 @@ class EmojiFormatter # @param [Array<CustomEmoji>] custom_emojis # @param [Hash] options # @option options [Boolean] :animate + # @option options [String] :style def initialize(html, custom_emojis, options = {}) raise ArgumentError unless html.html_safe? @@ -85,14 +86,29 @@ class EmojiFormatter def image_for_emoji(shortcode, emoji) original_url, static_url = emoji - if animate? - image_tag(original_url, draggable: false, class: 'emojione', alt: ":#{shortcode}:", title: ":#{shortcode}:") - else - image_tag(original_url, draggable: false, class: 'emojione custom-emoji', alt: ":#{shortcode}:", title: ":#{shortcode}:", data: { original: original_url, static: static_url }) - end + image_tag( + animate? ? original_url : static_url, + image_attributes.merge(alt: ":#{shortcode}:", title: ":#{shortcode}:", data: image_data_attributes(original_url, static_url)) + ) + end + + def image_attributes + { rel: 'emoji', draggable: false, width: 16, height: 16, class: image_class_names, style: image_style } + end + + def image_data_attributes(original_url, static_url) + { original: original_url, static: static_url } unless animate? + end + + def image_class_names + animate? ? 'emojione' : 'emojione custom-emoji' + end + + def image_style + @options[:style] end def animate? - @options[:animate] + @options[:animate] || @options.key?(:style) end end |