gemojione 2.5.0 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -0
- data/README.md +1 -0
- data/config/index.json +1791 -896
- data/lib/gemojione.rb +16 -2
- data/lib/gemojione/index.rb +2 -2
- data/lib/gemojione/version.rb +1 -1
- data/test/gemojione_test.rb +28 -0
- metadata +2 -2
data/lib/gemojione.rb
CHANGED
@@ -15,6 +15,8 @@ require "gemojione/railtie" if defined?(Rails)
|
|
15
15
|
module Gemojione
|
16
16
|
@asset_host = nil
|
17
17
|
@asset_path = nil
|
18
|
+
@default_size = nil
|
19
|
+
|
18
20
|
@escaper = defined?(EscapeUtils) ? EscapeUtils : CGI
|
19
21
|
|
20
22
|
def self.asset_host
|
@@ -33,6 +35,14 @@ module Gemojione
|
|
33
35
|
@asset_path = path
|
34
36
|
end
|
35
37
|
|
38
|
+
def self.default_size
|
39
|
+
@default_size
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.default_size=(size)
|
43
|
+
@default_size = size
|
44
|
+
end
|
45
|
+
|
36
46
|
def self.image_url_for_name(name)
|
37
47
|
emoji = index.find_by_name(name)
|
38
48
|
"#{asset_host}#{ File.join(asset_path, emoji['unicode']) }.png"
|
@@ -43,6 +53,10 @@ module Gemojione
|
|
43
53
|
image_url_for_name(emoji['name'])
|
44
54
|
end
|
45
55
|
|
56
|
+
def self.image_tag_for_moji(moji)
|
57
|
+
%Q{<img alt="#{moji}" class="emoji" src="#{ image_url_for_unicode_moji(moji) }"#{ default_size ? ' style="width: '+default_size+';"' : '' }>}
|
58
|
+
end
|
59
|
+
|
46
60
|
def self.replace_unicode_moji_with_images(string)
|
47
61
|
return string unless string
|
48
62
|
unless string.match(index.unicode_moji_regex)
|
@@ -51,7 +65,7 @@ module Gemojione
|
|
51
65
|
|
52
66
|
safe_string = safe_string(string.dup)
|
53
67
|
safe_string.gsub!(index.unicode_moji_regex) do |moji|
|
54
|
-
|
68
|
+
Gemojione.image_tag_for_moji(moji)
|
55
69
|
end
|
56
70
|
safe_string = safe_string.html_safe if safe_string.respond_to?(:html_safe)
|
57
71
|
|
@@ -68,7 +82,7 @@ module Gemojione
|
|
68
82
|
safe_string.gsub!(index.shortname_moji_regex) do |code|
|
69
83
|
name = code.tr(':','')
|
70
84
|
moji = index.find_by_name(name)['moji']
|
71
|
-
|
85
|
+
Gemojione.image_tag_for_moji(moji)
|
72
86
|
end
|
73
87
|
safe_string = safe_string.html_safe if safe_string.respond_to?(:html_safe)
|
74
88
|
|
data/lib/gemojione/index.rb
CHANGED
@@ -33,8 +33,8 @@ module Gemojione
|
|
33
33
|
@emoji_by_moji[moji] = emoji_hash if moji
|
34
34
|
end
|
35
35
|
|
36
|
-
@emoji_code_regex = /#{@emoji_by_code.keys.join('|')}/
|
37
|
-
@emoji_moji_regex = /#{@emoji_by_moji.keys.join('|')}/
|
36
|
+
@emoji_code_regex = /#{@emoji_by_code.keys.map{|ec| Regexp.escape(ec)}.join('|')}/
|
37
|
+
@emoji_moji_regex = /#{@emoji_by_moji.keys.map{|ec| Regexp.escape(ec)}.join('|')}/
|
38
38
|
end
|
39
39
|
|
40
40
|
def find_by_moji(moji)
|
data/lib/gemojione/version.rb
CHANGED
data/test/gemojione_test.rb
CHANGED
@@ -43,6 +43,30 @@ describe Gemojione do
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
+
describe 'default size' do
|
47
|
+
it 'should default to nil' do
|
48
|
+
assert_equal nil, Gemojione.default_size
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should be configurable' do
|
52
|
+
with_emoji_config(:default_size, '32px') do
|
53
|
+
assert_equal '32px', Gemojione.default_size
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'image_tag_for_moji' do
|
59
|
+
it 'should generate a clean img tag if default_size undefined' do
|
60
|
+
assert_equal '<img alt="🌀" class="emoji" src="http://localhost:3000/1F300.png">', Gemojione.image_tag_for_moji('🌀')
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should generate a img tag with style tag if default_size is defined' do
|
64
|
+
Gemojione.default_size='42px'
|
65
|
+
assert_equal '<img alt="🌀" class="emoji" src="http://localhost:3000/1F300.png" style="width: 42px;">', Gemojione.image_tag_for_moji('🌀')
|
66
|
+
Gemojione.default_size=nil
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
46
70
|
describe "replace_unicode_moji_with_images" do
|
47
71
|
it 'should return original string without emoji' do
|
48
72
|
assert_equal "foo", Gemojione.replace_unicode_moji_with_images('foo')
|
@@ -59,6 +83,10 @@ describe Gemojione do
|
|
59
83
|
assert_equal "I <img alt=\"❤\" class=\"emoji\" src=\"http://localhost:3000/2764.png\"> Emoji", replaced_string
|
60
84
|
end
|
61
85
|
|
86
|
+
it 'should escape regex breaker mojis' do
|
87
|
+
assert_equal "<img alt=\"*⃣\" class=\"emoji\" src=\"http://localhost:3000/002A-20E3.png\">", Gemojione.replace_unicode_moji_with_images('*⃣')
|
88
|
+
end
|
89
|
+
|
62
90
|
it 'should handle nil string' do
|
63
91
|
assert_equal nil, Gemojione.replace_unicode_moji_with_images(nil)
|
64
92
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gemojione
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Klabnik
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-06-
|
13
|
+
date: 2016-06-17 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json
|