Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add helper for named mojis as well #27

Merged
merged 1 commit into from
Jul 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ and call methods directly on your string to return the same results:
> 'I ❤ Emoji'.with_emoji_images
=> "I <img alt=\"❤\" class=\"emoji\" src=\"http://localhost:3000/assets/emoji/2764.png\"> Emoji"

> 'I :heart: Emoji'.with_emoji_names
=> "I <img alt=\"❤\" class=\"emoji\" src=\"http://localhost:3000/assets/emoji/2764.png\"> Emoji"

> 'heart'.image_url
> '❤'.image_url
=> "http://localhost:3000/assets/emoji/2764.png"
Expand Down
4 changes: 4 additions & 0 deletions lib/gemojione/string_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ def with_emoji_images
Gemojione.replace_unicode_moji_with_images(self)
end

def with_emoji_names
Gemojione.replace_named_moji_with_images(self)
end

def image_url
Gemojione.image_url_for_name(self.emoji_data['name'])
end
Expand Down
8 changes: 8 additions & 0 deletions test/string_ext_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
end
end

describe '#with_emoji_names' do
it 'should replace named moji with an img tag' do
base_string = "I :heart: Emoji"
replaced_string = base_string.with_emoji_names
assert_equal "I <img alt=\"❤\" class=\"emoji\" src=\"http://localhost:3000/2764.png\"> Emoji", replaced_string
end
end

describe '#image_url' do
it 'should generate image_url' do
assert_equal 'http://localhost:3000/1F300.png', '🌀'.image_url
Expand Down