twemoji 1.1.1 → 2.0.0
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 +42 -2
- data/README.md +71 -10
- data/lib/twemoji.rb +51 -17
- data/lib/twemoji/configuration.rb +25 -0
- data/lib/twemoji/map.rb +1 -1
- data/lib/twemoji/version.rb +1 -1
- data/test/configuration_test.rb +57 -0
- data/test/twemoji_test.rb +30 -10
- data/twemoji.gemspec +1 -1
- metadata +15 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0cf3827d6faa1a892e351a84b946f38161978ea
|
4
|
+
data.tar.gz: a9540545e514ae45ef5461b763b677ae26ddbf2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b4158105e7ca19745e4b5fbbbb3ff8193c9b64b250a33679aef00ec84d1a09021d3060f268313c16a064aa6b8e5e5a4ed9c5687bc76630a1f3674b9e9789c3c
|
7
|
+
data.tar.gz: fb9ad5b328e4b20e02e43a377993c7e6f7864c961b405aeb284ea80314460bc48c7870913600a94d6d5d9488617afd03fcc9cf8251e5423ff7e152954c4e567a
|
data/CHANGELOG.md
CHANGED
@@ -2,9 +2,49 @@
|
|
2
2
|
|
3
3
|
## Unreleased
|
4
4
|
|
5
|
-
##
|
5
|
+
## 2.0.0 - 2015.05.29
|
6
6
|
|
7
|
-
-
|
7
|
+
- **Breaking change**: `Tewmoji.parse` `img_attr` option changed to `img_attrs` [#16](https://github.com/jollygoodcode/twemoji/pull/16)
|
8
|
+
|
9
|
+
Old behaviour to specify `img` HTML attributes was passed in as a string to
|
10
|
+
`img_attr` option from `Twemoji.parse`. **This API is removed**.
|
11
|
+
|
12
|
+
Now please use `img_attrs` and passed in attribute-value pair you want in the
|
13
|
+
form of Hash. You can now specify any HTML attributes to rendered emoji `img`.
|
14
|
+
|
15
|
+
Note that the value of `img` tag attributes can be a proc-like object run
|
16
|
+
against emoji name. Say if you do not want the colon from the title attribute
|
17
|
+
of `img` tag. You can define a `no_colon = ->(name) { name.gsub(":", "") }`
|
18
|
+
then passed into `Twemoji.parse` like below example:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
> Twemoji.parse(":heart_eyes:", img_attrs: { title: no_colon })
|
22
|
+
<img
|
23
|
+
draggable="false"
|
24
|
+
title="heart_eyes"
|
25
|
+
alt=":heart_eyes:"
|
26
|
+
src="https://twemoji.maxcdn.com/16x16/1f60d.png"
|
27
|
+
class="twemoji"
|
28
|
+
>
|
29
|
+
```
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
Twemoji.configure do |config|
|
33
|
+
config.img_attrs = { style: "height: 1.3em;" }
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
- Twemoji Configuration [#15](https://github.com/jollygoodcode/twemoji/pull/15)
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
Twemoji.configure do |config|
|
41
|
+
config.asset_root = "https://twemoji.awesomecdn.com/"
|
42
|
+
config.file_ext = ".svg"
|
43
|
+
config.image_size = nil # only png need to set size
|
44
|
+
config.class_name = "twemoji"
|
45
|
+
config.img_attr = "style='height: 1.3em;'"
|
46
|
+
end
|
47
|
+
```
|
8
48
|
|
9
49
|
## 1.1.0 - 2015.02.27
|
10
50
|
|
data/README.md
CHANGED
@@ -8,7 +8,11 @@
|
|
8
8
|
[travis]: https://travis-ci.org/jollygoodcode/twemoji
|
9
9
|
[inch-doc]: http://inch-ci.org/github/jollygoodcode/twemoji
|
10
10
|
|
11
|
-
Twitter Emoji
|
11
|
+
Twitter [opensourced Twitter Emoji](http://twitter.github.io/twemoji/) and the official JavaScript implementation is available at [twemoji](https://github.com/twitter/twemoji).
|
12
|
+
|
13
|
+
This RubyGem `twemoji` is a minimum implementation of Twitter Emoji in Ruby so that you can haz emoji in your Ruby/Rails apps too!
|
14
|
+
|
15
|
+
__Note:__ This gem might not implement all the features available in the JavaScript implementation.
|
12
16
|
|
13
17
|
## Installation
|
14
18
|
|
@@ -28,7 +32,7 @@ Or install it yourself as:
|
|
28
32
|
|
29
33
|
### Ruby 1.9.3 Support
|
30
34
|
|
31
|
-
@bramswenson has put
|
35
|
+
@bramswenson has put in effort to support Ruby 1.9.3, please use [his forked branch](https://github.com/bramswenson/twemoji/tree/ruby-1.9.3):
|
32
36
|
|
33
37
|
```ruby
|
34
38
|
gem "twemoji", github: "bramswenson/twemoji", branch: "ruby-1.9.3"
|
@@ -36,7 +40,33 @@ gem "twemoji", github: "bramswenson/twemoji", branch: "ruby-1.9.3"
|
|
36
40
|
|
37
41
|
## Integration
|
38
42
|
|
39
|
-
- [Integration with
|
43
|
+
- [Integration with `HTML::Pipeline`](https://github.com/jollygoodcode/twemoji/wiki/Integrate-with-HTML%3A%3APipeline)
|
44
|
+
|
45
|
+
## Rails Helper
|
46
|
+
|
47
|
+
`$ touch app/helpers/emoji_helper.rb`
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
module EmojiHelper
|
51
|
+
def emojify(content, **options)
|
52
|
+
Twemoji.parse(h(content), options).html_safe if content.present?
|
53
|
+
end
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
In your ERb view:
|
58
|
+
|
59
|
+
```erb
|
60
|
+
<%= emojify "I like chocolate :heart_eyes:!", image_size: "36x36" %>
|
61
|
+
```
|
62
|
+
|
63
|
+
will render
|
64
|
+
|
65
|
+
```
|
66
|
+
I like chocolate <img class="emoji" draggable="false" title=":heart_eyes:" alt="😍" src="https://twemoji.maxcdn.com/36x36/1f60d.png">!
|
67
|
+
```
|
68
|
+
|
69
|
+
More options could be passed in, please see [Twemoji.parse options](https://github.com/jollygoodcode/twemoji#twemojiparse-options) for more details.
|
40
70
|
|
41
71
|
## Usage
|
42
72
|
|
@@ -100,7 +130,7 @@ gem "twemoji", github: "bramswenson/twemoji", branch: "ruby-1.9.3"
|
|
100
130
|
|
101
131
|
##### `asset_root`
|
102
132
|
|
103
|
-
Default assets root url
|
133
|
+
Default assets root url. Defaults to `https://twemoji.maxcdn.com/`:
|
104
134
|
|
105
135
|
```ruby
|
106
136
|
> Twemoji.parse 'I like chocolate :heart_eyes:!', asset_root: "foocdn.com"
|
@@ -109,7 +139,7 @@ Default assets root url, by default will be `https://twemoji.maxcdn.com/`:
|
|
109
139
|
|
110
140
|
##### `file_ext`
|
111
141
|
|
112
|
-
Default assets file extensions
|
142
|
+
Default assets file extensions. Defaults to `.png`.
|
113
143
|
|
114
144
|
```ruby
|
115
145
|
> Twemoji.parse 'I like chocolate :heart_eyes:!', file_ext: ".svg"
|
@@ -118,7 +148,9 @@ Default assets file extensions, by default `.png`.
|
|
118
148
|
|
119
149
|
##### `image_size`
|
120
150
|
|
121
|
-
Default assets/folder size
|
151
|
+
Default assets/folder size. Defaults to `"16x16"`.
|
152
|
+
|
153
|
+
Sizes available via Twitter CDN: `16`, `36`, `72`.
|
122
154
|
|
123
155
|
```ruby
|
124
156
|
> Twemoji.parse 'I like chocolate :heart_eyes:!', image_size: "72x72"
|
@@ -127,20 +159,31 @@ Default assets/folder size, by default `"16x16"`. Available via Twitter CDN: `16
|
|
127
159
|
|
128
160
|
##### `class_name`
|
129
161
|
|
130
|
-
Default
|
162
|
+
Default image CSS class name. Defaults to `"emoji"`.
|
131
163
|
|
132
164
|
```ruby
|
133
165
|
> Twemoji.parse 'I like chocolate :heart_eyes:!', class_name: "superemoji"
|
134
166
|
=> "I like chocolate <img class='superemoji' draggable='false' title=':heart_eyes:' alt='😍' src='https://twemoji.maxcdn.com/16x16/1f60d.png'>!"
|
135
167
|
```
|
136
168
|
|
137
|
-
##### `
|
169
|
+
##### `img_attrs`
|
170
|
+
|
171
|
+
List of image attributes for the `img` tag. Optional.
|
138
172
|
|
139
173
|
```ruby
|
140
|
-
> Twemoji.parse("I like chocolate :heart_eyes:!", class_name: 'twemoji',
|
174
|
+
> Twemoji.parse("I like chocolate :heart_eyes:!", class_name: 'twemoji', img_attrs: { style: "height: 1.3em;" })
|
141
175
|
=> "I like chocolate <img class='twemoji' draggable='false' title=':heart_eyes:' alt='😍' style='height: 1.3em;' src='https://twemoji.maxcdn.com/16x16/1f60d.png'>!"
|
142
176
|
```
|
143
177
|
|
178
|
+
attribute value can apply proc-like object, remove `:` from title attribute:
|
179
|
+
|
180
|
+
```ruby
|
181
|
+
> no_colons = ->(name) { name.gsub(":", "") }
|
182
|
+
|
183
|
+
> Twemoji.parse("I like chocolate :heart_eyes:!", class_name: 'twemoji', img_attrs: { title: no_colons })
|
184
|
+
=> "I like chocolate <img class='twemoji' draggable='false' title='heart_eyes' alt='😍' src='https://twemoji.maxcdn.com/16x16/1f60d.png'>!"
|
185
|
+
```
|
186
|
+
|
144
187
|
#### `Twemoji.emoji_pattern`
|
145
188
|
|
146
189
|
```ruby
|
@@ -148,6 +191,24 @@ Default img css class name, by default `"emoji"`.
|
|
148
191
|
=> /(:smile:|:laughing:| ... |:womens:|:x:|:zero:)/
|
149
192
|
```
|
150
193
|
|
194
|
+
## Configuration
|
195
|
+
|
196
|
+
`Twemoji.parse` options can be given in configure block:
|
197
|
+
|
198
|
+
```ruby
|
199
|
+
Twemoji.configure do |config|
|
200
|
+
config.asset_root = "https://twemoji.awesomecdn.com/"
|
201
|
+
config.file_ext = ".svg"
|
202
|
+
config.image_size = nil # only png need to set size
|
203
|
+
config.class_name = "twemoji"
|
204
|
+
config.img_attrs = { style: "height: 1.3em;" }
|
205
|
+
end
|
206
|
+
```
|
207
|
+
|
208
|
+
## Attribution Requirements
|
209
|
+
|
210
|
+
Please follow the [Attribution Requirements](https://github.com/twitter/twemoji#attribution-requirements) as stated on the official Twemoji (JS) repo.
|
211
|
+
|
151
212
|
## Contributing
|
152
213
|
|
153
214
|
1. Fork it ( https://github.com/jollygoodcode/twemoji/fork )
|
@@ -158,7 +219,7 @@ Default img css class name, by default `"emoji"`.
|
|
158
219
|
|
159
220
|
## Credits
|
160
221
|
|
161
|
-
A huge THANK YOU to all our [contributors]
|
222
|
+
A huge THANK YOU to all our [contributors](https://github.com/jollygoodcode/twemoji/graphs/contributors)! :heart:
|
162
223
|
|
163
224
|
This project is maintained by [Jolly Good Code](http://www.jollygoodcode.com).
|
164
225
|
|
data/lib/twemoji.rb
CHANGED
@@ -2,6 +2,7 @@ require "nokogiri"
|
|
2
2
|
|
3
3
|
require "twemoji/version"
|
4
4
|
require "twemoji/map"
|
5
|
+
require "twemoji/configuration"
|
5
6
|
|
6
7
|
# Twemoji is a Ruby implementation, parses your text, replace emoji text
|
7
8
|
# with corresponding emoji image. Default emoji images are from Twiiter CDN.
|
@@ -97,22 +98,20 @@ module Twemoji
|
|
97
98
|
# @option options [String] (optional) asset_root Asset root url to serve emoji.
|
98
99
|
# @option options [String] (optional) file_ext File extension.
|
99
100
|
# @option options [String] (optional) image_size Emoji image's size 16, 36, 72 applicable if specify .png.
|
100
|
-
# @option options [String] (optional)
|
101
|
-
# @option options [String] (optional) img_attr Emoji image's img tag attribute.
|
101
|
+
# @option options [String] (optional) img_attrs Emoji image's img tag attributes.
|
102
102
|
#
|
103
103
|
# @return [String] Original text with all occurrences of emoji text
|
104
104
|
# replaced by emoji image according to given options.
|
105
|
-
def self.parse(text, asset_root:
|
106
|
-
file_ext:
|
107
|
-
image_size:
|
108
|
-
class_name:
|
109
|
-
|
105
|
+
def self.parse(text, asset_root: Twemoji.configuration.asset_root,
|
106
|
+
file_ext: Twemoji.configuration.file_ext,
|
107
|
+
image_size: Twemoji.configuration.image_size,
|
108
|
+
class_name: Twemoji.configuration.class_name,
|
109
|
+
img_attrs: Twemoji.configuration.img_attrs)
|
110
110
|
|
111
111
|
options[:asset_root] = asset_root
|
112
112
|
options[:file_ext] = file_ext
|
113
113
|
options[:image_size] = image_size
|
114
|
-
options[:
|
115
|
-
options[:img_attr] = img_attr
|
114
|
+
options[:img_attrs] = { class: class_name }.merge! img_attrs
|
116
115
|
|
117
116
|
if text.is_a?(Nokogiri::HTML::DocumentFragment)
|
118
117
|
parse_document(text)
|
@@ -165,7 +164,7 @@ module Twemoji
|
|
165
164
|
# @return [Nokogiri::HTML::DocumentFragment] Parsed document.
|
166
165
|
# @private
|
167
166
|
def self.parse_document(doc)
|
168
|
-
doc.
|
167
|
+
doc.search('text()').each do |node|
|
169
168
|
content = node.to_html
|
170
169
|
next if !content.include?(":")
|
171
170
|
next if has_ancestor?(node, %w(pre code tt))
|
@@ -206,12 +205,9 @@ module Twemoji
|
|
206
205
|
# @return [String] Emoji image tag generated by name and options.
|
207
206
|
# @private
|
208
207
|
def self.img_tag(name)
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
else
|
213
|
-
"<img class='#{options[:class_name]}' draggable='false' title='#{name}' alt='#{unicode}' src='#{emoji_url(name)}'>"
|
214
|
-
end
|
208
|
+
img_attrs_hash = default_attrs(name).merge! customized_attrs(name)
|
209
|
+
|
210
|
+
%(<img #{hash_to_html_attrs(img_attrs_hash)}>)
|
215
211
|
end
|
216
212
|
|
217
213
|
# Returns emoji url by given name and options from `Twemoji.parse`.
|
@@ -227,7 +223,45 @@ module Twemoji
|
|
227
223
|
elsif options[:file_ext] == ".svg"
|
228
224
|
File.join(options[:asset_root], "svg", "#{code}.svg")
|
229
225
|
else
|
230
|
-
fail "
|
226
|
+
fail "Unsupported file extension: #{options[:file_ext]}"
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
# Returns user customized img attributes. If attribute value is any proc-like
|
231
|
+
# object, will call it and the emoji name will be passed as argument.
|
232
|
+
#
|
233
|
+
# @param name [String] Emoji name.
|
234
|
+
# @return Hash of customized attributes
|
235
|
+
# @private
|
236
|
+
def self.customized_attrs(name)
|
237
|
+
custom_img_attributes = options[:img_attrs]
|
238
|
+
|
239
|
+
# run value filters where given
|
240
|
+
custom_img_attributes.each do |key, value|
|
241
|
+
custom_img_attributes[key] = value.call(name) if value.respond_to?(:call)
|
231
242
|
end
|
232
243
|
end
|
244
|
+
|
245
|
+
# Default img attributes: draggable, title, alt, src.
|
246
|
+
#
|
247
|
+
# @param name [String] Emoji name.
|
248
|
+
# @return Hash of default attributes
|
249
|
+
# @private
|
250
|
+
def self.default_attrs(name)
|
251
|
+
{
|
252
|
+
draggable: "false".freeze,
|
253
|
+
title: name,
|
254
|
+
alt: render_unicode(name),
|
255
|
+
src: emoji_url(name)
|
256
|
+
}
|
257
|
+
end
|
258
|
+
|
259
|
+
# Coverts hash of attributes into HTML attributes.
|
260
|
+
#
|
261
|
+
# @param hash [Hash] Hash of attributes.
|
262
|
+
# @return [String] HTML attributes suitable for use in tag
|
263
|
+
# @private
|
264
|
+
def self.hash_to_html_attrs(hash)
|
265
|
+
hash.map { |attr, value| %(#{attr}="#{value}") }.join(" ")
|
266
|
+
end
|
233
267
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Twemoji
|
2
|
+
def self.configuration
|
3
|
+
@configuration ||= Configuration.new
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.configuration=(configuration)
|
7
|
+
@configuration = configuration
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.configure
|
11
|
+
yield configuration
|
12
|
+
end
|
13
|
+
|
14
|
+
class Configuration
|
15
|
+
attr_accessor :asset_root, :file_ext, :image_size, :class_name, :img_attrs
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
@asset_root = "https://twemoji.maxcdn.com/".freeze
|
19
|
+
@file_ext = ".png".freeze
|
20
|
+
@image_size = "16x16".freeze
|
21
|
+
@class_name = "emoji".freeze
|
22
|
+
@img_attrs = {}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/twemoji/map.rb
CHANGED
@@ -834,7 +834,7 @@ module Twemoji
|
|
834
834
|
":womens:" => "1f6ba",
|
835
835
|
":x:" => "274c",
|
836
836
|
":zero:" => "30-20e3"
|
837
|
-
}.each { |
|
837
|
+
}.each { |k, v| k.freeze; v.freeze }.freeze
|
838
838
|
|
839
839
|
# Emoji Codepoint to Text mappings. This hash is frozen.
|
840
840
|
#
|
data/lib/twemoji/version.rb
CHANGED
@@ -0,0 +1,57 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class TwemojiConfigurationTest < Minitest::Test
|
4
|
+
def teardown
|
5
|
+
Twemoji.configuration = nil
|
6
|
+
Twemoji.configure {}
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_configuration_defaults
|
10
|
+
assert_equal "https://twemoji.maxcdn.com/", Twemoji.configuration.asset_root
|
11
|
+
assert_equal ".png", Twemoji.configuration.file_ext
|
12
|
+
assert_equal "16x16", Twemoji.configuration.image_size
|
13
|
+
assert_equal "emoji", Twemoji.configuration.class_name
|
14
|
+
assert_equal Hash(nil), Twemoji.configuration.img_attrs
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_configuration_asset_root
|
18
|
+
Twemoji.configure do |config|
|
19
|
+
config.asset_root = "https://twemoji.awesomecdn.com/"
|
20
|
+
end
|
21
|
+
|
22
|
+
assert_equal "https://twemoji.awesomecdn.com/", Twemoji.configuration.asset_root
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_configuration_file_ext
|
26
|
+
Twemoji.configure do |config|
|
27
|
+
config.file_ext = ".svg"
|
28
|
+
end
|
29
|
+
|
30
|
+
assert_equal ".svg", Twemoji.configuration.file_ext
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_configuration_image_size
|
34
|
+
Twemoji.configure do |config|
|
35
|
+
config.file_ext = ".png"
|
36
|
+
config.image_size = "36x36"
|
37
|
+
end
|
38
|
+
|
39
|
+
assert_equal "36x36", Twemoji.configuration.image_size
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_configuration_class_name
|
43
|
+
Twemoji.configure do |config|
|
44
|
+
config.class_name = "twemoji"
|
45
|
+
end
|
46
|
+
|
47
|
+
assert_equal "twemoji", Twemoji.configuration.class_name
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_configuration_img_attrs
|
51
|
+
Twemoji.configure do |config|
|
52
|
+
config.img_attrs = { style: "height: 1.3em" }
|
53
|
+
end
|
54
|
+
|
55
|
+
assert_equal Hash(style: "height: 1.3em"), Twemoji.configuration.img_attrs
|
56
|
+
end
|
57
|
+
end
|
data/test/twemoji_test.rb
CHANGED
@@ -42,26 +42,26 @@ class TwemojiTest < Minitest::Test
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def test_parse_html_string
|
45
|
-
expected =
|
45
|
+
expected = %(I like chocolate <img draggable="false" title=":heart_eyes:" alt="😍" src="https://twemoji.maxcdn.com/16x16/1f60d.png" class="emoji">!)
|
46
46
|
|
47
47
|
assert_equal expected, Twemoji.parse("I like chocolate :heart_eyes:!")
|
48
48
|
end
|
49
49
|
|
50
50
|
def test_parse_document
|
51
51
|
doc = Nokogiri::HTML::DocumentFragment.parse("<p>I like chocolate :heart_eyes:!</p>")
|
52
|
-
expected = '<p>I like chocolate <img
|
52
|
+
expected = '<p>I like chocolate <img draggable="false" title=":heart_eyes:" alt="😍" src="https://twemoji.maxcdn.com/16x16/1f60d.png" class="emoji">!</p>'
|
53
53
|
|
54
54
|
assert_equal expected, Twemoji.parse(doc).to_html
|
55
55
|
end
|
56
56
|
|
57
57
|
def test_parse_option_asset_root
|
58
|
-
expected =
|
58
|
+
expected = %(I like chocolate <img draggable="false" title=":heart_eyes:" alt="😍" src="https://emoji.bestcdn.com/16x16/1f60d.png" class="emoji">!)
|
59
59
|
|
60
60
|
assert_equal expected, Twemoji.parse("I like chocolate :heart_eyes:!", asset_root: 'https://emoji.bestcdn.com')
|
61
61
|
end
|
62
62
|
|
63
63
|
def test_parse_option_file_ext_svg
|
64
|
-
expected =
|
64
|
+
expected = %(I like chocolate <img draggable="false" title=":heart_eyes:" alt="😍" src="https://twemoji.maxcdn.com/svg/1f60d.svg" class="emoji">!)
|
65
65
|
|
66
66
|
assert_equal expected, Twemoji.parse("I like chocolate :heart_eyes:!", file_ext: '.svg')
|
67
67
|
end
|
@@ -71,25 +71,45 @@ class TwemojiTest < Minitest::Test
|
|
71
71
|
Twemoji.parse("I like chocolate :heart_eyes:!", file_ext: '.gif')
|
72
72
|
end
|
73
73
|
|
74
|
-
assert_equal "
|
74
|
+
assert_equal "Unsupported file extension: .gif", exception.message
|
75
75
|
end
|
76
76
|
|
77
77
|
def test_parse_option_image_size
|
78
|
-
expected =
|
78
|
+
expected = %(I like chocolate <img draggable="false" title=":heart_eyes:" alt="😍" src="https://twemoji.maxcdn.com/72x72/1f60d.png" class="emoji">!)
|
79
79
|
|
80
80
|
assert_equal expected, Twemoji.parse("I like chocolate :heart_eyes:!", file_ext: ".png", image_size: "72x72")
|
81
81
|
end
|
82
82
|
|
83
83
|
def test_parse_option_class_name
|
84
|
-
expected =
|
84
|
+
expected = %(I like chocolate <img draggable="false" title=":heart_eyes:" alt="😍" src="https://twemoji.maxcdn.com/16x16/1f60d.png" class="twemoji">!)
|
85
85
|
|
86
86
|
assert_equal expected, Twemoji.parse("I like chocolate :heart_eyes:!", class_name: 'twemoji')
|
87
87
|
end
|
88
88
|
|
89
|
-
def
|
90
|
-
expected =
|
89
|
+
def test_parse_option_single_img_attr
|
90
|
+
expected = %(I like chocolate <img draggable="false" title=":heart_eyes:" alt="😍" src="https://twemoji.maxcdn.com/16x16/1f60d.png" class="twemoji" style="height: 1.3em;">!)
|
91
91
|
|
92
|
-
assert_equal expected, Twemoji.parse("I like chocolate :heart_eyes:!", class_name: 'twemoji',
|
92
|
+
assert_equal expected, Twemoji.parse("I like chocolate :heart_eyes:!", class_name: 'twemoji', img_attrs: { style: 'height: 1.3em;' })
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_parse_option_multiple_img_attrs
|
96
|
+
expected = %(I like chocolate <img draggable="false" title=":heart_eyes:" alt="😍" src="https://twemoji.maxcdn.com/16x16/1f60d.png" class="twemoji" style="height: 1.3em;" width="20">!)
|
97
|
+
|
98
|
+
assert_equal expected, Twemoji.parse("I like chocolate :heart_eyes:!", class_name: 'twemoji', img_attrs: { style: 'height: 1.3em;', width: "20" })
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_parse_option_img_attr_callable
|
102
|
+
shortname_filter = ->(name) { name.gsub(":", "") }
|
103
|
+
|
104
|
+
img_attrs = {
|
105
|
+
style: "height: 1.3em;",
|
106
|
+
title: shortname_filter,
|
107
|
+
alt: shortname_filter,
|
108
|
+
}
|
109
|
+
|
110
|
+
expected = %(I like chocolate <img draggable="false" title="heart_eyes" alt="heart_eyes" src="https://twemoji.maxcdn.com/16x16/1f60d.png" class="twemoji" style="height: 1.3em;">!)
|
111
|
+
|
112
|
+
assert_equal expected, Twemoji.parse("I like chocolate :heart_eyes:!", class_name: 'twemoji', img_attrs: img_attrs)
|
93
113
|
end
|
94
114
|
|
95
115
|
def test_emoji_pattern
|
data/twemoji.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twemoji
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juanito
|
@@ -9,22 +9,28 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-05-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - "
|
18
|
+
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 1.
|
20
|
+
version: '1.4'
|
21
|
+
- - "<="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.6.5
|
21
24
|
type: :runtime
|
22
25
|
prerelease: false
|
23
26
|
version_requirements: !ruby/object:Gem::Requirement
|
24
27
|
requirements:
|
25
|
-
- - "
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '1.4'
|
31
|
+
- - "<="
|
26
32
|
- !ruby/object:Gem::Version
|
27
|
-
version: 1.6.
|
33
|
+
version: 1.6.5
|
28
34
|
description: 'A RubyGem to convert :heart: to Twitter cdn url'
|
29
35
|
email:
|
30
36
|
- katehuang0320@gmail.com
|
@@ -40,8 +46,10 @@ files:
|
|
40
46
|
- README.md
|
41
47
|
- Rakefile
|
42
48
|
- lib/twemoji.rb
|
49
|
+
- lib/twemoji/configuration.rb
|
43
50
|
- lib/twemoji/map.rb
|
44
51
|
- lib/twemoji/version.rb
|
52
|
+
- test/configuration_test.rb
|
45
53
|
- test/test_helper.rb
|
46
54
|
- test/twemoji_test.rb
|
47
55
|
- twemoji.gemspec
|
@@ -65,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
73
|
version: '0'
|
66
74
|
requirements: []
|
67
75
|
rubyforge_project:
|
68
|
-
rubygems_version: 2.4.
|
76
|
+
rubygems_version: 2.4.5
|
69
77
|
signing_key:
|
70
78
|
specification_version: 4
|
71
79
|
summary: 'A RubyGem to convert :heart: to Twitter cdn url'
|