emoji 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +15 -1
- data/lib/emoji.rb +14 -3
- data/lib/emoji/version.rb +1 -1
- data/test/emoji_test.rb +13 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3db53a871c5e23c6351a7f65f4a42d553cf9939
|
4
|
+
data.tar.gz: 887e181e6e54b5f55426c7a2ad0a338cf50660e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48be0c44cad71b861e291e96a47bed6f49e355e743b0c2b03feb63151471a7efeba82d9226a2749a97c9230bfeb592d9229c33241141011e901609d7121e689f
|
7
|
+
data.tar.gz: 9a6a4ec187f2d1afeb022627c5bb3abe462368b14f49a8762d0b050bcf504006fa0cf46ce50a1890be7c4ac8a6f021dd138bdf47e6ce9462eaa1928c6adf87d3
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
A Ruby gem. For emoji. For everyone. :heart:
|
4
4
|
|
5
|
-
[](https://travis-ci.org/wpeterson/emoji)
|
6
6
|
|
7
7
|
This gem exposes the [Phantom Open Emoji library](https://github.com/Genshin/PhantomOpenEmoji) unicode/image assets and APIs for working with them.
|
8
8
|
|
@@ -62,6 +62,9 @@ Emoji Library Index APIs:
|
|
62
62
|
|
63
63
|
> index.find_by_moji('❤')
|
64
64
|
=> {"moji"=>"❤", "name"=>"heart", "name-ja"=>"ハート", "category"=>"abstract", "unicode"=>"2764"}
|
65
|
+
|
66
|
+
> index.find_by_unicode('2764')
|
67
|
+
=> {"moji"=>"❤", "name"=>"heart", "name-ja"=>"ハート", "category"=>"abstract", "unicode"=>"2764"}
|
65
68
|
```
|
66
69
|
Default configuration integrates with Rails, but you can change it with an initializer:
|
67
70
|
|
@@ -95,6 +98,17 @@ and call methods directly on your string to return the same results:
|
|
95
98
|
=> {"moji"=>"❤", "name"=>"heart", "name-ja"=>"ハート", "category"=>"abstract", "unicode"=>"2764"}
|
96
99
|
```
|
97
100
|
|
101
|
+
## Emoji Asset host
|
102
|
+
By default, if used with Rails this gem will inherit Rails configured `Rails.asset_host`. Otherwise, you will need to configure the `Emoji.asset_host` as a string URL or a lambda/proc.
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
# String URL
|
106
|
+
Emoji.asset_host = 'http://your.com'
|
107
|
+
|
108
|
+
# Custom Host Proc, takes asset path as a param
|
109
|
+
Emoji.asset_host = lambda {|path| path.size % 2 == 0 ? 'http://even.com' : 'http://odd.com'}
|
110
|
+
```
|
111
|
+
|
98
112
|
## HTML Safety and Performance
|
99
113
|
|
100
114
|
This gem uses pure ruby code for compatibility with different Ruby virtual machines. However, there can be significant performance gains to escaping incoming HTML strings using optimized, native code in the `escape_utils` gem.
|
data/lib/emoji.rb
CHANGED
@@ -28,9 +28,12 @@ module Emoji
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def self.parse_and_validate_asset_host(asset_host_spec)
|
31
|
-
|
32
|
-
|
31
|
+
return '' unless asset_host_spec
|
32
|
+
return asset_host_spec if asset_host_spec.respond_to?(:call)
|
33
|
+
unless asset_host_spec.kind_of?(String)
|
34
|
+
raise 'Invalid Emoji.asset_host, should be a hostname or URL prefix'
|
33
35
|
end
|
36
|
+
return '' unless asset_host_spec.size >= 1
|
34
37
|
|
35
38
|
# Special Case for 'hostname:port' style URIs, not parse properly by URI.parse
|
36
39
|
if asset_host_spec.match(/^[^:]+:\d+$/)
|
@@ -91,8 +94,16 @@ module Emoji
|
|
91
94
|
@use_plaintext_alt_tags = bool
|
92
95
|
end
|
93
96
|
|
97
|
+
def self.asset_host_for_asset(asset_path)
|
98
|
+
return asset_host if asset_host.kind_of?(String)
|
99
|
+
|
100
|
+
asset_host.call(asset_path)
|
101
|
+
end
|
102
|
+
|
94
103
|
def self.image_url_for_name(name)
|
95
|
-
"#{
|
104
|
+
path = "#{ File.join(asset_path, name) }.png"
|
105
|
+
host = asset_host_for_asset(path)
|
106
|
+
"#{host}#{path}"
|
96
107
|
end
|
97
108
|
|
98
109
|
def self.image_url_for_unicode_moji(moji)
|
data/lib/emoji/version.rb
CHANGED
data/test/emoji_test.rb
CHANGED
@@ -13,6 +13,12 @@ describe Emoji do
|
|
13
13
|
assert_equal '/cyclone.png', Emoji.image_url_for_name('cyclone')
|
14
14
|
end
|
15
15
|
end
|
16
|
+
|
17
|
+
it 'should use proc asset_host' do
|
18
|
+
with_emoji_config(:asset_host, lambda {|path| 'http://proc.com' }) do
|
19
|
+
assert_equal 'http://proc.com/cyclone.png', Emoji.image_url_for_name('cyclone')
|
20
|
+
end
|
21
|
+
end
|
16
22
|
end
|
17
23
|
|
18
24
|
describe "image_url_for_unicode_moji" do
|
@@ -65,6 +71,13 @@ describe Emoji do
|
|
65
71
|
assert_equal '', Emoji.asset_host
|
66
72
|
end
|
67
73
|
end
|
74
|
+
|
75
|
+
it 'should allow proc' do
|
76
|
+
asset_proc = lambda {|path| "proc.com"}
|
77
|
+
with_emoji_config(:asset_host, asset_proc) do
|
78
|
+
assert_equal asset_proc, Emoji.asset_host
|
79
|
+
end
|
80
|
+
end
|
68
81
|
end
|
69
82
|
|
70
83
|
describe "asset_path" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: emoji
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Klabnik
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-07-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|