emoji 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 174fb12d6b0501388fb5ff4017d09367b6aa5d03
4
- data.tar.gz: 59ab1a8c80158fe30fe85589ef1dd16ffd5cabf6
3
+ metadata.gz: c3db53a871c5e23c6351a7f65f4a42d553cf9939
4
+ data.tar.gz: 887e181e6e54b5f55426c7a2ad0a338cf50660e7
5
5
  SHA512:
6
- metadata.gz: b6f16c86fcea49a221d4fe0e4945ade156f2c362907731568cd1d31f3cb7fe3be606638ac4413eafaac200e000ce00913ae25b7a9f28f3ad23b760539599e308
7
- data.tar.gz: 45172ab36a11c69ab9709b0565354ca4c54bf89931a315cf96d79ebfd184276cc3b3c546aba9aa900042d0de0f0e618221e69d2b4e3e0e47c164ed4dee830b22
6
+ metadata.gz: 48be0c44cad71b861e291e96a47bed6f49e355e743b0c2b03feb63151471a7efeba82d9226a2749a97c9230bfeb592d9229c33241141011e901609d7121e689f
7
+ data.tar.gz: 9a6a4ec187f2d1afeb022627c5bb3abe462368b14f49a8762d0b050bcf504006fa0cf46ce50a1890be7c4ac8a6f021dd138bdf47e6ce9462eaa1928c6adf87d3
@@ -1,5 +1,9 @@
1
1
  # Releases / Changes
2
2
 
3
+ ## 1.0.5
4
+
5
+ * Adds support for dynamic Emoji.asset_host as a proc (ala Rails.asset_host)
6
+
3
7
  ## 1.0.4
4
8
 
5
9
  * Moved Homepage/repo to wpeterson/emoji
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  A Ruby gem. For emoji. For everyone. :heart:
4
4
 
5
- [![Build Status](https://travis-ci.org/steveklabnik/emoji.svg?branch=master)](https://travis-ci.org/steveklabnik/emoji)
5
+ [![Build Status](https://travis-ci.org/wpeterson/emoji.svg?branch=master)](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.
@@ -28,9 +28,12 @@ module Emoji
28
28
  end
29
29
 
30
30
  def self.parse_and_validate_asset_host(asset_host_spec)
31
- unless asset_host_spec && asset_host_spec.size >= 1
32
- return ''
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
- "#{asset_host}#{ File.join(asset_path, name) }.png"
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)
@@ -1,3 +1,3 @@
1
1
  module Emoji
2
- VERSION = "1.0.4"
2
+ VERSION = "1.0.5"
3
3
  end
@@ -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
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-04-28 00:00:00.000000000 Z
12
+ date: 2015-07-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json