about summary refs log tree commit diff
path: root/app/lib/emoji_formatter.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/lib/emoji_formatter.rb')
-rw-r--r--app/lib/emoji_formatter.rb28
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