Skip to content

Commit

Permalink
Make image_filename customizable
Browse files Browse the repository at this point in the history
  • Loading branch information
elektronaut committed Dec 12, 2014
1 parent df1b6fa commit ac3620c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions lib/emoji/character.rb
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions test/emoji_test.rb
Expand Up @@ -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")

Expand Down

0 comments on commit ac3620c

Please sign in to comment.