twemoji 3.1.3 → 3.1.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 14667837f508c92cdb75ea5b56cc68c1e7793106
4
- data.tar.gz: 21d5d277ec2ce8063b193675bfc0f5ea1cd389f8
2
+ SHA256:
3
+ metadata.gz: 2234c251d175548199d9753ca53bd56f76b2dcfa12a08930fc16723376b5561d
4
+ data.tar.gz: bd38221b6e87c2e15725466e660bdaf798dd85a408cbe5b75f564a469240ee9d
5
5
  SHA512:
6
- metadata.gz: e6dcbe76bff292e714d36e2d19b8803545ff511d7c81c5ebc9807807100e86ddfec25d971dabbb7a02f9929a67201266d62997509029a50e200ed99402f637b5
7
- data.tar.gz: 4b049e6a4f7d7e049ee2650cd078c936e6733ede733fc4b39a2274166e29ff2876a52c1e18b00f2bdb2fba1823dd7d847d8c2044af14b13cd97044a8824538c6
6
+ metadata.gz: 42cd46ca1bb4672f93b6a2b8914ceeb8959d1b2c49b0eba9416b9a8481343be86da46d40688e2d02834b336d2049e071d87731ef2c5217f0b72a48352d992945
7
+ data.tar.gz: 1dfad31671c59fd8f29610a0a6d2af49d5f95c79abb54dd04f098c21a8ffa6f051dfc75adee6e42f7b6a669477f55d8abd46f754645b8ece50e698f3e7f8e767
@@ -2,6 +2,27 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 3.1.8 - 2020.12.21
6
+
7
+ - Fix retained memory.
8
+
9
+ ## 3.1.7 - 2020.09.28
10
+
11
+ - Relax required ruby version
12
+
13
+ ## 3.1.6 - 2019.12.21
14
+
15
+ - Moved expensive computations to constant [#53](https://github.com/jollygoodcode/twemoji/pull/53)
16
+
17
+ ## 3.1.5 - 2019.06.02
18
+
19
+ - Introduced `Twemoji::Utils::Unicode.unpack` [#51](https://github.com/jollygoodcode/twemoji/pull/51)
20
+ - Do not set attribute on generated element if not specified [#49](https://github.com/jollygoodcode/twemoji/pull/49)
21
+
22
+ ## 3.1.4 - 2017.07.22
23
+
24
+ - Fixes woman skin 6 emoji [#44](https://github.com/jollygoodcode/twemoji/pull/44)
25
+
5
26
  ## 3.1.3 - 2017.07.22
6
27
 
7
28
  - Fixes name of kiss emoji [#42](https://github.com/jollygoodcode/twemoji/pull/42)
@@ -17,8 +38,8 @@
17
38
  ## 3.1.0 - 2016.12.13
18
39
 
19
40
  - `Twemoji.parse` can now parse unicode values, too [#35](https://github.com/jollygoodcode/twemoji/pull/35)
20
- * [New API] `Twemoji.emoji_pattern_unicode` - List all emoji unicodes in a regex
21
- * [New API] `Twemoji.emoji_pattern_all` - List all emoji names and unicodes in a regex
41
+ - [New API] `Twemoji.emoji_pattern_unicode` - List all emoji unicodes in a regex
42
+ - [New API] `Twemoji.emoji_pattern_all` - List all emoji names and unicodes in a regex
22
43
 
23
44
  ## 3.0.2 - 2016.11.15
24
45
 
@@ -136,15 +157,15 @@
136
157
 
137
158
  **New Methods**:
138
159
 
139
- * [`Twemoji.find_by`](https://github.com/jollygoodcode/twemoji/blob/fe2810ddbe1f2cfdb496bcdd9e1576ba1e05eb06/lib/twemoji.rb#L9-L35) now accepts `unicode` keyword argument (either a raw unicode or escaped-unicode string) to find emoji text
160
+ - [`Twemoji.find_by`](https://github.com/jollygoodcode/twemoji/blob/fe2810ddbe1f2cfdb496bcdd9e1576ba1e05eb06/lib/twemoji.rb#L9-L35) now accepts `unicode` keyword argument (either a raw unicode or escaped-unicode string) to find emoji text
140
161
 
141
- * Add [`Twemoji.find_by_unicode`](https://github.com/jollygoodcode/twemoji/blob/fe2810ddbe1f2cfdb496bcdd9e1576ba1e05eb06/lib/twemoji.rb#L61-L71) to find emoji text by raw emoji unicode or escaped-unicode string
162
+ - Add [`Twemoji.find_by_unicode`](https://github.com/jollygoodcode/twemoji/blob/fe2810ddbe1f2cfdb496bcdd9e1576ba1e05eb06/lib/twemoji.rb#L61-L71) to find emoji text by raw emoji unicode or escaped-unicode string
142
163
 
143
- * Add [`Twemoji.render_unicode`](https://github.com/jollygoodcode/twemoji/blob/fe2810ddbe1f2cfdb496bcdd9e1576ba1e05eb06/lib/twemoji.rb#L73-L86) to render raw emoji unicode from emoji text or emoji code
164
+ - Add [`Twemoji.render_unicode`](https://github.com/jollygoodcode/twemoji/blob/fe2810ddbe1f2cfdb496bcdd9e1576ba1e05eb06/lib/twemoji.rb#L73-L86) to render raw emoji unicode from emoji text or emoji code
144
165
 
145
166
  **Changes**:
146
167
 
147
- * `img` tag's `alt` changes from emoji text like `:heart_eyes:` to actual unicode `"😍"`
168
+ - `img` tag's `alt` changes from emoji text like `:heart_eyes:` to actual unicode `"😍"`
148
169
 
149
170
  - Restrict Nokogiri to (1.4..1.6.5). @JuanitoFatas [#3](https://github.com/jollygoodcode/twemoji/pull/3)
150
171
 
data/README.md CHANGED
@@ -297,7 +297,7 @@ To properly support emoji, the document character must be set to UTF-8. This can
297
297
 
298
298
  ## Attribution Requirements
299
299
 
300
- **IMPORTANT:** Please follow the [Attribution Requirements](https://github.com/twitter/twemoji#attribution-requirements) as stated on the official Twemoji (JS) repo.
300
+ **IMPORTANT:** Please follow the [Attribution Requirements](https://github.com/twitter/twemoji#attribution-requirements) as stated on the official Twemoji (JavaScript) repo.
301
301
 
302
302
  ## Contributing
303
303
 
@@ -5,6 +5,7 @@ require "json"
5
5
  require "twemoji/version"
6
6
  require "twemoji/map"
7
7
  require "twemoji/configuration"
8
+ require "twemoji/utils/unicode"
8
9
 
9
10
  # Twemoji is a Ruby implementation, parses your text, replace emoji text
10
11
  # with corresponding emoji image. Default emoji images are from Twiiter CDN.
@@ -112,7 +113,7 @@ module Twemoji
112
113
 
113
114
  options[:asset_root] = asset_root
114
115
  options[:file_ext] = file_ext
115
- options[:img_attrs] = { class: class_name }.merge! img_attrs
116
+ options[:img_attrs] = { class: class_name }.merge(img_attrs)
116
117
 
117
118
  if text.is_a?(Nokogiri::HTML::DocumentFragment)
118
119
  parse_document(text)
@@ -125,7 +126,7 @@ module Twemoji
125
126
  #
126
127
  # @return [RegExp] A Regular expression consists of all emojis text.
127
128
  def self.emoji_pattern
128
- @emoji_pattern ||= /(#{codes.keys.map { |name| Regexp.quote(name) }.join("|") })/
129
+ EMOJI_PATTERN
129
130
  end
130
131
 
131
132
  # Return all emoji patterns' regular expressions in unicode.
@@ -133,21 +134,31 @@ module Twemoji
133
134
  #
134
135
  # @return [RegExp] A Regular expression consists of all emojis unicode.
135
136
  def self.emoji_pattern_unicode
136
- @emoji_pattern_unicode ||= /(#{sorted_codepoint_values.map { |name| Regexp.quote(name.split('-').collect {|n| n.hex}.pack("U*")) }.join("|") })/
137
+ EMOJI_PATTERN_UNICODE
137
138
  end
138
139
 
139
140
  # Return all emoji patterns' regular expressions in unicode and name.
140
141
  #
141
142
  # @return [RegExp] A Regular expression consists of all emojis unicode codepoint and names.
142
143
  def self.emoji_pattern_all
143
- names = codes.keys.map { |name| Regexp.quote(name) }.join("|")
144
- codepoints = sorted_codepoint_values.map { |name| Regexp.quote(name.split('-').collect {|n| n.hex}.pack("U*")) }.join("|")
145
-
146
- @emoji_pattern_all ||= /(#{names}|#{codepoints})/
144
+ EMOJI_PATTERN_ALL
147
145
  end
148
146
 
149
147
  private
150
148
 
149
+ # Return sorted codepoint values by descending length.
150
+ #
151
+ # @return [Array] An array of emoji codepoint values sorted by descending length
152
+ def self.sorted_codepoint_values
153
+ # has to be sorted to match the combined codepoint (2-3 char emojis) before single char emojis
154
+ @sorted_codepoint_values ||= invert_codes.keys.sort_by {|key| key.length }.reverse
155
+ end
156
+
157
+ EMOJI_PATTERN = /#{codes.keys.map { |name| Regexp.quote(name) }.join("|")}/.freeze
158
+ EMOJI_PATTERN_UNICODE = /#{sorted_codepoint_values.map { |name| Regexp.quote(name.split('-').collect {|n| n.hex}.pack("U*")) }.join("|")}/.freeze
159
+ EMOJI_PATTERN_ALL = /(#{EMOJI_PATTERN}|#{EMOJI_PATTERN_UNICODE})/.freeze
160
+ private_constant :EMOJI_PATTERN, :EMOJI_PATTERN_UNICODE, :EMOJI_PATTERN_ALL
161
+
151
162
  # Ensure text is a string.
152
163
  #
153
164
  # @param text [String] Text to ensure to be a string.
@@ -309,7 +320,7 @@ module Twemoji
309
320
  # @return String representation of unicode codepoint
310
321
  # @private
311
322
  def self.unicode_to_str(unicode)
312
- unicode.split("").map { |r| "%x" % r.ord }.join("-")
323
+ Twemoji::Utils::Unicode.unpack(unicode)
313
324
  end
314
325
 
315
326
  # Coverts hash of attributes into HTML attributes.
@@ -318,14 +329,6 @@ module Twemoji
318
329
  # @return [String] HTML attributes suitable for use in tag
319
330
  # @private
320
331
  def self.hash_to_html_attrs(hash)
321
- hash.map { |attr, value| %(#{attr}="#{value}") }.join(" ")
322
- end
323
-
324
- # Return sorted codepoint values by descending length.
325
- #
326
- # @return [Array] An array of emoji codepoint values sorted by descending length
327
- def self.sorted_codepoint_values
328
- # has to be sorted to match the combined codepoint (2-3 char emojis) before single char emojis
329
- @sorted_codepoint_values ||= invert_codes.keys.sort_by {|key| key.length }.reverse
332
+ hash.reject { |key, value| value.nil? || value == '' }.map { |attr, value| %(#{attr}="#{value}") }.join(" ")
330
333
  end
331
334
  end
@@ -797,7 +797,7 @@
797
797
  ":woman::skin-tone-3:": https://twemoji.maxcdn.com/2/72x72/1f469-1f3fc.png
798
798
  ":woman::skin-tone-4:": https://twemoji.maxcdn.com/2/72x72/1f469-1f3fd.png
799
799
  ":woman::skin-tone-5:": https://twemoji.maxcdn.com/2/72x72/1f469-1f3fe.png
800
- ":woman::skin-tone-6": https://twemoji.maxcdn.com/2/72x72/1f469-1f3ff.png
800
+ ":woman::skin-tone-6:": https://twemoji.maxcdn.com/2/72x72/1f469-1f3ff.png
801
801
  ":woman:": https://twemoji.maxcdn.com/2/72x72/1f469.png
802
802
  ":woman-woman-boy:": https://twemoji.maxcdn.com/2/72x72/1f469-200d-1f469-200d-1f466.png
803
803
  ":woman-woman-boy-boy:": https://twemoji.maxcdn.com/2/72x72/1f469-200d-1f469-200d-1f466-200d-1f466.png
@@ -797,7 +797,7 @@
797
797
  ":woman::skin-tone-3:": https://twemoji.maxcdn.com/2/svg/1f469-1f3fc.svg
798
798
  ":woman::skin-tone-4:": https://twemoji.maxcdn.com/2/svg/1f469-1f3fd.svg
799
799
  ":woman::skin-tone-5:": https://twemoji.maxcdn.com/2/svg/1f469-1f3fe.svg
800
- ":woman::skin-tone-6": https://twemoji.maxcdn.com/2/svg/1f469-1f3ff.svg
800
+ ":woman::skin-tone-6:": https://twemoji.maxcdn.com/2/svg/1f469-1f3ff.svg
801
801
  ":woman:": https://twemoji.maxcdn.com/2/svg/1f469.svg
802
802
  ":woman-woman-boy:": https://twemoji.maxcdn.com/2/svg/1f469-200d-1f469-200d-1f466.svg
803
803
  ":woman-woman-boy-boy:": https://twemoji.maxcdn.com/2/svg/1f469-200d-1f469-200d-1f466-200d-1f466.svg
@@ -797,7 +797,7 @@
797
797
  ":woman::skin-tone-3:": 1f469-1f3fc
798
798
  ":woman::skin-tone-4:": 1f469-1f3fd
799
799
  ":woman::skin-tone-5:": 1f469-1f3fe
800
- ":woman::skin-tone-6": 1f469-1f3ff
800
+ ":woman::skin-tone-6:": 1f469-1f3ff
801
801
  ":woman:": 1f469
802
802
  ":woman-woman-boy:": 1f469-200d-1f469-200d-1f466
803
803
  ":woman-woman-boy-boy:": 1f469-200d-1f469-200d-1f466-200d-1f466
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Twemoji
4
+ module Utils
5
+ module Unicode
6
+ # Convert raw unicode to string key version.
7
+ #
8
+ # e.g. 🇲🇾 converts to "1f1f2-1f1fe"
9
+ #
10
+ # @param unicode [String] Unicode codepoint.
11
+ # @param connector [String] (optional) connector to join codepoints
12
+ #
13
+ # @return [String] codepoints of unicode join by connector argument, defaults to "-".
14
+ def self.unpack(unicode, connector: "-")
15
+ unicode.split("").map { |r| "%x" % r.ord }.join(connector)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Twemoji
4
- VERSION = "3.1.3"
4
+ VERSION = "3.1.8"
5
5
  end
@@ -17,7 +17,5 @@ Gem::Specification.new do |spec|
17
17
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f =~ %r(^(test)/) }
18
18
  spec.require_paths = %w(lib)
19
19
 
20
- spec.required_ruby_version = "~> 2.0"
21
-
22
20
  spec.add_dependency "nokogiri", "~> 1.6"
23
21
  end
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: 3.1.3
4
+ version: 3.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juanito
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-07-22 00:00:00.000000000 Z
12
+ date: 2020-12-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -49,6 +49,7 @@ files:
49
49
  - lib/twemoji/map.rb
50
50
  - lib/twemoji/png.rb
51
51
  - lib/twemoji/svg.rb
52
+ - lib/twemoji/utils/unicode.rb
52
53
  - lib/twemoji/version.rb
53
54
  - twemoji.gemspec
54
55
  homepage: https://github.com/jollygoodcode/twemoji
@@ -61,17 +62,16 @@ require_paths:
61
62
  - lib
62
63
  required_ruby_version: !ruby/object:Gem::Requirement
63
64
  requirements:
64
- - - "~>"
65
+ - - ">="
65
66
  - !ruby/object:Gem::Version
66
- version: '2.0'
67
+ version: '0'
67
68
  required_rubygems_version: !ruby/object:Gem::Requirement
68
69
  requirements:
69
70
  - - ">="
70
71
  - !ruby/object:Gem::Version
71
72
  version: '0'
72
73
  requirements: []
73
- rubyforge_project:
74
- rubygems_version: 2.6.12
74
+ rubygems_version: 3.0.3
75
75
  signing_key:
76
76
  specification_version: 4
77
77
  summary: 'A RubyGem to convert :heart: to Twitter cdn url'