emoji 1.0.5 → 1.0.6

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: c3db53a871c5e23c6351a7f65f4a42d553cf9939
4
- data.tar.gz: 887e181e6e54b5f55426c7a2ad0a338cf50660e7
3
+ metadata.gz: 85b117fc2248c58f4b7c1b271121cefcc58ecd7a
4
+ data.tar.gz: 1b78b3e8d1d096e644110f03d41fdaf64d6ddf50
5
5
  SHA512:
6
- metadata.gz: 48be0c44cad71b861e291e96a47bed6f49e355e743b0c2b03feb63151471a7efeba82d9226a2749a97c9230bfeb592d9229c33241141011e901609d7121e689f
7
- data.tar.gz: 9a6a4ec187f2d1afeb022627c5bb3abe462368b14f49a8762d0b050bcf504006fa0cf46ce50a1890be7c4ac8a6f021dd138bdf47e6ce9462eaa1928c6adf87d3
6
+ metadata.gz: 10e36d5aab8e0a94fc2f28cf9ab8b0b59786127089dd6c86f876a10821480a9be6f0103a9ecc1cc15357097cfaed232c0a945d3194099737b5f1258a3b092a5e
7
+ data.tar.gz: 0ae62138344caec64c023abfd93731e31202bfbc4ff0d3df241e04c6fc21fe02715403c2d657bd7262587667dc80e3173886a05577dad024c0c795b32a623211
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Releases / Changes
2
2
 
3
+ ## 1.0.6
4
+
5
+ * Adds `Emoji.replace_unicode_moji_with_name()` for Markdown
6
+
3
7
  ## 1.0.5
4
8
 
5
9
  * Adds support for dynamic Emoji.asset_host as a proc (ala Rails.asset_host)
data/README.md CHANGED
@@ -1,16 +1,27 @@
1
1
  # Emoji
2
+ [![Build Status](https://travis-ci.org/wpeterson/emoji.svg?branch=master)](https://travis-ci.org/wpeterson/emoji)
2
3
 
3
4
  A Ruby gem. For emoji. For everyone. :heart:
4
5
 
5
- [![Build Status](https://travis-ci.org/wpeterson/emoji.svg?branch=master)](https://travis-ci.org/wpeterson/emoji)
6
-
7
6
  This gem exposes the [Phantom Open Emoji library](https://github.com/Genshin/PhantomOpenEmoji) unicode/image assets and APIs for working with them.
8
7
 
9
- Easily lookup emoji name, unicode character, or image assets and convert emoji representations.
8
+ Easily look up emoji's name, unicode character, or image assets and convert it into emoji representations.
9
+
10
+ ## Table of Contents
11
+ - [Installation](#installation)
12
+ - [Usage](#usage)
13
+ - [Image Replacement APIs](#image-replacement-apis)
14
+ - [Emoji Library Index APIs](#emoji-library-index-apis)
15
+ - [String Helper Methods](#string-helper-methods)
16
+ - [Emoji Asset Host](#emoji-asset-host)
17
+ - [HTML Safety and Performance](#html-safety-and-performance)
18
+ - [Contributors :heart:](#contributors-heart)
19
+ - [Contributing](#contributing)
20
+
10
21
 
11
22
  ## Installation
12
23
 
13
- Add this line to your application's Gemfile:
24
+ First, add this line to your application's Gemfile:
14
25
 
15
26
  ```ruby
16
27
  gem 'emoji'
@@ -23,8 +34,8 @@ And then execute:
23
34
  Or install it yourself as:
24
35
 
25
36
  $ gem install emoji
26
-
27
- Install emoji image library assets:
37
+
38
+ Finally, install the emoji image library assets:
28
39
 
29
40
  $ rake emoji:install_assets
30
41
  ====================================================================
@@ -37,9 +48,9 @@ Install emoji image library assets:
37
48
 
38
49
  ## Usage
39
50
 
40
- You can use this gem to replace unicode emoji characters with img tags linking to the appropriate emoji image.
51
+ You can use this gem to replace unicode emoji characters with `img` tags linking to the appropriate emoji image.
41
52
 
42
- Image Replacement APIs:
53
+ ### Image Replacement APIs:
43
54
 
44
55
  ```ruby
45
56
  > Emoji.replace_unicode_moji_with_images('I ❤ Emoji')
@@ -52,7 +63,7 @@ Image Replacement APIs:
52
63
  => "http://localhost:3000/assets/emoji/heart.png"
53
64
  ```
54
65
 
55
- Emoji Library Index APIs:
66
+ ### Emoji Library Index APIs:
56
67
 
57
68
  ```ruby
58
69
  > index = Emoji::Index.new
@@ -67,20 +78,20 @@ Emoji Library Index APIs:
67
78
  => {"moji"=>"❤", "name"=>"heart", "name-ja"=>"ハート", "category"=>"abstract", "unicode"=>"2764"}
68
79
  ```
69
80
  Default configuration integrates with Rails, but you can change it with an initializer:
70
-
71
- ```ruby
81
+
82
+ ```ruby
72
83
  # config/initializers/emoji.rb
73
84
  Emoji.asset_host = "emoji.cdn.com"
74
85
  Emoji.asset_path = '/assets/emoji'
75
86
  Emoji.use_plaintext_alt_tags = true
76
87
  ```
77
88
 
78
- String Helper Methods:
89
+ ### String Helper Methods:
79
90
 
80
- You can also
91
+ You can also include the string helper module
81
92
 
82
93
  ```ruby
83
- include 'emoji/string_ext'
94
+ require 'emoji/string_ext'
84
95
  ```
85
96
 
86
97
  and call methods directly on your string to return the same results:
@@ -98,8 +109,8 @@ and call methods directly on your string to return the same results:
98
109
  => {"moji"=>"❤", "name"=>"heart", "name-ja"=>"ハート", "category"=>"abstract", "unicode"=>"2764"}
99
110
  ```
100
111
 
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.
112
+ ## Emoji Asset Host
113
+ By default when used with Rails, this gem will inherit Rails configured `Rails.asset_host`. Otherwise, you will need to manually configure the `Emoji.asset_host` as a string URL or a lambda/proc.
103
114
 
104
115
  ```ruby
105
116
  # String URL
@@ -111,9 +122,9 @@ Emoji.asset_host = lambda {|path| path.size % 2 == 0 ? 'http://even.com' : 'http
111
122
 
112
123
  ## HTML Safety and Performance
113
124
 
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.
125
+ 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.
115
126
 
116
- The emoji gem will try to use `escape_utils` if it's available, but does not require it. [Benchmarks show a 10x-100x improvement](https://gist.github.com/wpeterson/c851be471bd91868716c) in HTML escaping performance, based on the size of the string being processed.
127
+ The `emoji` gem will try to use `escape_utils` if it's available, but does not require it. [Benchmarks show a 10x-100x improvement](https://gist.github.com/wpeterson/c851be471bd91868716c) in HTML escaping performance, based on the size of the string being processed.
117
128
 
118
129
  To enable native HTML escaping, add this line to your application's Gemfile:
119
130
 
@@ -122,7 +133,7 @@ gem 'escape_utils'
122
133
  ```
123
134
  ## Contributors: :heart:
124
135
 
125
- This project was spawned from conversation at the BurlingtonRB conference between Steve/Winfield. Together they built the initial gem. Huge thanks to everyone else who's submitted code and work to the project.
136
+ This project was spawned from conversation at the [BurlingtonRB conference](http://www.burlingtonrubyconference.com/) between [Steve](https://github.com/steveklabnik)/[Winfield](https://github.com/wpeterson). Together, they built the the initial gem. Huge thanks to everyone else who's submitted code and work to the project.
126
137
 
127
138
  * [@steveklabnik](https://github.com/steveklabnik): Created this project and made it all happen
128
139
  * [@wpeterson](https://github.com/wpeterson): gem implementation
@@ -134,10 +145,11 @@ This project was spawned from conversation at the BurlingtonRB conference betwee
134
145
  * [@tumes](https://github.com/tumes): Plaintext Emoji Alt Tags
135
146
  * [@poporul](https://github.com/poporul): Emoji::Index Refactoring
136
147
  * [@dilkhush](https://github.com/dilkhush): Emoji::Index Search by Unicode
148
+ * [@cromulus](https://github.com/cromulus): Emoji.replace_unicode_moji_with_name() API
137
149
 
138
150
  ## Contributing
139
151
 
140
- 1. Fork it
152
+ 1. Fork the repo
141
153
  2. Bundle Install (`bundle install`)
142
154
  3. Run the Tests (`rake test`)
143
155
  2. Create your feature branch (`git checkout -b my-new-feature`)
data/lib/emoji.rb CHANGED
@@ -47,8 +47,8 @@ module Emoji
47
47
  hostname = uri.hostname || uri.path
48
48
  port_string = extract_port_string(uri)
49
49
  end
50
-
51
- "#{ scheme_string }#{ hostname }#{ port_string }"
50
+
51
+ "#{ scheme_string }#{ hostname }#{ port_string }"
52
52
  end
53
53
 
54
54
  def self.parse_asset_host_uri(asset_host_spec)
@@ -132,6 +132,22 @@ module Emoji
132
132
  safe_string
133
133
  end
134
134
 
135
+ def self.replace_unicode_moji_with_name(string)
136
+ return string unless string
137
+ unless string.match(index.unicode_moji_regex)
138
+ return safe_string(string)
139
+ end
140
+
141
+ safe_string = safe_string(string.dup)
142
+ safe_string.gsub!(index.unicode_moji_regex) do |moji|
143
+ emoji = index.find_by_moji(moji)
144
+ %Q{:#{emoji['name']}:}
145
+ end
146
+ safe_string = safe_string.html_safe if safe_string.respond_to?(:html_safe)
147
+
148
+ safe_string
149
+ end
150
+
135
151
  def self.safe_string(string)
136
152
  if string.respond_to?(:html_safe?) && string.html_safe?
137
153
  string
data/lib/emoji/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Emoji
2
- VERSION = "1.0.5"
2
+ VERSION = "1.0.6"
3
3
  end
data/test/emoji_test.rb CHANGED
@@ -104,6 +104,16 @@ describe Emoji do
104
104
  end
105
105
  end
106
106
 
107
+ describe 'replace_unicode_moji_with_name' do
108
+ it 'should return original string without emoji' do
109
+ assert_equal "foo", Emoji.replace_unicode_moji_with_name('foo')
110
+ end
111
+ it 'should replace an emoji with its ascii name' do
112
+ base_string = "I ❤ Emoji"
113
+ assert_equal "I :heart: Emoji", Emoji.replace_unicode_moji_with_name(base_string)
114
+ end
115
+ end
116
+
107
117
  describe "replace_unicode_moji_with_images" do
108
118
  it 'should return original string without emoji' do
109
119
  assert_equal "foo", Emoji.replace_unicode_moji_with_images('foo')
@@ -159,7 +169,7 @@ describe Emoji do
159
169
  replaced_string = string.stub(:html_safe?, true) do
160
170
  Emoji.replace_unicode_moji_with_images(string)
161
171
  end
162
-
172
+
163
173
  assert_equal "<img alt=\"❤\" class=\"emoji\" src=\"http://localhost:3000/heart.png\"><a href=\"harmless\">", replaced_string
164
174
  end
165
175
 
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.5
4
+ version: 1.0.6
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-07-09 00:00:00.000000000 Z
12
+ date: 2016-06-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -605,7 +605,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
605
605
  version: '0'
606
606
  requirements: []
607
607
  rubyforge_project:
608
- rubygems_version: 2.4.6
608
+ rubygems_version: 2.0.3
609
609
  signing_key:
610
610
  specification_version: 4
611
611
  summary: 'A Ruby gem. For emoji. For everyone. :heart:'