diff --git a/README.md b/README.md index c87925e7..d9394702 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,14 @@ emoji.image_filename #=> "music.png" As you create new emoji, you must ensure that you also create and put the images they reference by their `image_filename` to your assets directory. +You can customize `image_filename` with: + +```ruby +emoji = Emoji.create("music") do |char| + char.image_filename = "subdirectory/my_emoji.gif" +end +``` + For existing emojis, you can edit the list of aliases or add new tags in an edit block: ```ruby diff --git a/lib/emoji/character.rb b/lib/emoji/character.rb index c85b6d54..a3632a00 100644 --- a/lib/emoji/character.rb +++ b/lib/emoji/character.rb @@ -51,7 +51,19 @@ def hex_inspect self.class.hex_inspect(raw) end + attr_writer :image_filename + def image_filename + if defined? @image_filename + @image_filename + else + default_image_filename + end + end + + private + + def default_image_filename if custom? '%s.png' % name else diff --git a/test/emoji_test.rb b/test/emoji_test.rb index 4ff43ed4..2f90c480 100644 --- a/test/emoji_test.rb +++ b/test/emoji_test.rb @@ -94,6 +94,18 @@ class EmojiTest < TestCase end end + test "create with custom filename" do + emoji = Emoji.create("music") do |char| + char.image_filename = "some_path/my_emoji.gif" + end + + begin + assert_equal "some_path/my_emoji.gif", emoji.image_filename + ensure + Emoji.all.pop + end + end + test "create without block" do emoji = Emoji.create("music")