From 023441883e4e5bf321d205ead09a6456e7f04874 Mon Sep 17 00:00:00 2001 From: Jerry Cheung Date: Tue, 7 Oct 2014 14:50:46 -0700 Subject: [PATCH] drop support for gemoji ~> 1.0 --- Gemfile | 2 +- lib/html/pipeline/emoji_filter.rb | 24 ++++++------------------ test/html/pipeline/emoji_filter_test.rb | 14 +++++++------- 3 files changed, 14 insertions(+), 26 deletions(-) diff --git a/Gemfile b/Gemfile index 5d48f313..19874abf 100644 --- a/Gemfile +++ b/Gemfile @@ -11,7 +11,7 @@ end group :test do gem "minitest", "~> 5.3" gem "rinku", "~> 1.7", :require => false - gem "gemoji", "~> 1.0", :require => false + gem "gemoji", "~> 2.0", :require => false gem "RedCloth", "~> 4.2.9", :require => false gem "github-markdown", "~> 0.5", :require => false gem "email_reply_parser", "~> 0.5", :require => false diff --git a/lib/html/pipeline/emoji_filter.rb b/lib/html/pipeline/emoji_filter.rb index f54a470e..3fee8994 100644 --- a/lib/html/pipeline/emoji_filter.rb +++ b/lib/html/pipeline/emoji_filter.rb @@ -25,7 +25,7 @@ def call end doc end - + # Implementation of validate hook. # Errors should raise exceptions or use an existing validator. def validate @@ -79,24 +79,12 @@ def emoji_pattern self.class.emoji_pattern end - # Detect gemoji v2 which has a new API - # https://github.com/jch/html-pipeline/pull/129 - if Emoji.respond_to?(:all) - def self.emoji_names - Emoji.all.map(&:aliases).flatten.sort - end - - def emoji_filename(name) - Emoji.find_by_alias(name).image_filename - end - else - def self.emoji_names - Emoji.names - end + def self.emoji_names + Emoji.all.map(&:aliases).flatten.sort + end - def emoji_filename(name) - "#{::CGI.escape(name)}.png" - end + def emoji_filename(name) + Emoji.find_by_alias(name).image_filename end end end diff --git a/test/html/pipeline/emoji_filter_test.rb b/test/html/pipeline/emoji_filter_test.rb index bcdd1f02..ad986c41 100644 --- a/test/html/pipeline/emoji_filter_test.rb +++ b/test/html/pipeline/emoji_filter_test.rb @@ -2,22 +2,22 @@ class HTML::Pipeline::EmojiFilterTest < Minitest::Test EmojiFilter = HTML::Pipeline::EmojiFilter - + def test_emojify filter = EmojiFilter.new("

:shipit:

", {:asset_root => 'https://foo.com'}) doc = filter.call assert_match "https://foo.com/emoji/shipit.png", doc.search('img').attr('src').value end - + def test_uri_encoding filter = EmojiFilter.new("

:+1:

", {:asset_root => 'https://foo.com'}) doc = filter.call - assert_match "https://foo.com/emoji/%2B1.png", doc.search('img').attr('src').value + assert_match "https://foo.com/emoji/unicode/1f44d.png", doc.search('img').attr('src').value end - + def test_required_context_validation - exception = assert_raises(ArgumentError) { - EmojiFilter.call("", {}) + exception = assert_raises(ArgumentError) { + EmojiFilter.call("", {}) } assert_match /:asset_root/, exception.message end @@ -25,7 +25,7 @@ def test_required_context_validation def test_custom_asset_path filter = EmojiFilter.new("

:+1:

", {:asset_path => ':file_name', :asset_root => 'https://foo.com'}) doc = filter.call - assert_match "https://foo.com/%2B1.png", doc.search('img').attr('src').value + assert_match "https://foo.com/unicode/1f44d.png", doc.search('img').attr('src').value end def test_not_emojify_in_code_tags