somemoji 0.3.1 → 0.3.2

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: 0ccf34291e0c2e7e64661b6e82874ef7e3c321a3
4
- data.tar.gz: bed7df7665ad7fd7a6a44cb5b647435251c4c5e6
3
+ metadata.gz: cb3b0923dfa3d0f5b047e54028fc235ce6bc475a
4
+ data.tar.gz: c00021c451b2482a7c1a559b90de99747208c8d4
5
5
  SHA512:
6
- metadata.gz: e6a1c6081784a870617846ad450cc54346d4f8746d52fe4635dbc44aab7e87e5d72d72f099a236e016e9928e6fbe67440f6158762890ff5fe3a193601c33e34e
7
- data.tar.gz: 893fb85300fb414eabc2d0d03899d7c5d5abeefddb67a443d58a534f97db90197f5d0231019416fe7d318bfd1b569fce4d53004797605ca0e2bca099752b321c
6
+ metadata.gz: 0fb106ddabc5900bc370c61a90a2af8bd37554e380fba0e64fd333ae8069c986d27c1fe0e978e339e73021457c09a4ae60c57b93c9521844dfb0466e0f7a1127
7
+ data.tar.gz: 8efdff1491f24a93f517464eb058046813d6fb65f1914b07351f34e0e0c0bb2ed28c8fac50b9fdf7c120ad7397c8068038f691d2d0065c608a87a480802a121c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## v0.3.2
2
+
3
+ - Fix bug: nil.map raises error on no code_points emoji :bug:
4
+ - Change Somemoji::Emoji#character so that it may return nil
5
+
1
6
  ## v0.3.1
2
7
 
3
8
  - Add Noto emoji extractor
data/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # Somemoji
2
2
 
3
- [![CircleCI](https://circleci.com/gh/r7kamura/somemoji.svg?style=svg)](https://circleci.com/gh/r7kamura/somemoji)
3
+ [![Gem Version](https://badge.fury.io/rb/somemoji.svg)](https://badge.fury.io/rb/somemoji)
4
4
  [![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](http://www.rubydoc.info/github/r7kamura/somemoji)
5
+ [![CircleCI](https://circleci.com/gh/r7kamura/somemoji.svg?style=svg)](https://circleci.com/gh/r7kamura/somemoji)
5
6
 
6
7
  A grand unified emoji mapper for some emoji providers.
7
8
 
@@ -35,3 +36,74 @@ gem install somemoji
35
36
  ## Documentation
36
37
 
37
38
  See API documentation at http://www.rubydoc.info/github/r7kamura/somemoji.
39
+
40
+ ## Use cases
41
+
42
+ ### Replace emoji codes
43
+
44
+ ```ruby
45
+ Somemoji.emoji_one_emoji_collection.replace_code("I :heart: Emoji") do |emoji|
46
+ %(<img alt="#{emoji.character}" class="emoji" src="/assets/emoji/#{emoji.base_path}.png">)
47
+ end
48
+ #=> 'I <img alt="❤" class="emoji" src="/assets/emoji/unicode/2764.png"> Emoji'
49
+ ```
50
+
51
+ ### Replace emoji characters
52
+
53
+ ```ruby
54
+ Somemoji.noto_emoji_collection.replace_character("I 💗 Emoji") do |emoji|
55
+ %(<img alt="#{emoji.character}" class="emoji" src="/assets/emoji/#{emoji.base_path}.png">)
56
+ end
57
+ #=> 'I <img alt="💗" class="emoji" src="/assets/emoji/unicode/1f497.png"> Emoji'
58
+ ```
59
+
60
+ ### Custom emojis
61
+
62
+ ```ruby
63
+ custom_emoji_collection = Somemoji.emoji_one_emoji_collection + Somemoji::EmojiCollection.new(
64
+ [
65
+ Somemoji::Emoji.new(code: "foo"),
66
+ Somemoji::Emoji.new(code: "bar"),
67
+ ]
68
+ )
69
+ custom_emoji_collection.find_by_code("foo").class #=> Somemoji::Emoji
70
+ custom_emoji_collection.find_by_code("bar").class #=> Somemoji::Emoji
71
+ custom_emoji_collection.find_by_code("100").class #=> Somemoji::Emoji
72
+ custom_emoji_collection.replace_code("I :bar: Emoji") do |emoji|
73
+ %(<img alt="#{emoji.character || emoji.code}" class="emoji" src="/assets/emoji/#{emoji.base_path}.png">)
74
+ end #=> 'I <img alt="bar" class="emoji" src="/assets/emoji/bar.png"> Emoji'
75
+ ```
76
+
77
+ ### HTML::Pipeline integration
78
+
79
+ ```ruby
80
+ class EmojiFilter < ::HTML::Pipeline::Filter
81
+ IGNORED_ANCESTOR_ELEMENT_NAMES = %w(
82
+ code
83
+ pre
84
+ tt
85
+ )
86
+
87
+ # @note Implementation for HTML::Pipeline::Filter
88
+ def call
89
+ doc.search(".//text()").each do |node|
90
+ unless has_ancestor?(node, IGNORED_ANCESTOR_ELEMENT_NAMES)
91
+ node.replace(
92
+ ::Somemoji.twemoji_emoji_collection.replace_code(node.to_html) do |emoji|
93
+ %W(
94
+ <img
95
+ alt="#{emoji.code}"
96
+ class="emoji"
97
+ height="20"
98
+ src="/images/emoji/#{emoji.base_path}.png"
99
+ title=":#{emoji.code}:"
100
+ width="20">
101
+ ).join(" ")
102
+ end
103
+ )
104
+ end
105
+ end
106
+ doc
107
+ end
108
+ end
109
+ ```
@@ -76,7 +76,7 @@ module Somemoji
76
76
  @ascii_arts = ascii_arts || []
77
77
  @category = category
78
78
  @code = code
79
- @code_points = code_points
79
+ @code_points = code_points || []
80
80
  @code_points_alternates = code_points_alternates || []
81
81
  @keywords = keywords || []
82
82
  @name = name
@@ -100,11 +100,13 @@ module Somemoji
100
100
  end
101
101
  end
102
102
 
103
- # @return [String] a String representation of an emoji (if code points are defined on this emoji)
103
+ # @return [String, nil] a String representation from its code points
104
104
  def character
105
- code_points.map do |code_point|
106
- code_point.to_i(16)
107
- end.pack("U*")
105
+ unless code_points.empty?
106
+ code_points.map do |code_point|
107
+ code_point.to_i(16)
108
+ end.pack("U*")
109
+ end
108
110
  end
109
111
  end
110
112
  end
@@ -103,9 +103,9 @@ module Somemoji
103
103
  # @return [String] a replaced result
104
104
  # @example
105
105
  # Somemoji.emoji_collection.replace_character("I ❤ Emoji") do |emoji|
106
- # %(<img alt="#{emoji.character}" class="emoji" src="/assets/emoji/#{emoji.code_points.join('-').downcase}.png">)
106
+ # %(<img alt="#{emoji.character}" class="emoji" src="/assets/emoji/#{emoji.base_path}.png">)
107
107
  # end
108
- # #=> 'I <img alt="❤" class="emoji" src="/assets/emoji/2764.png"> Emoji'
108
+ # #=> 'I <img alt="❤" class="emoji" src="/assets/emoji/unicode/2764.png"> Emoji'
109
109
  def replace_character(string, &block)
110
110
  string.gsub(character_pattern) do |character|
111
111
  block.call(find_by_character(character), character)
@@ -117,9 +117,9 @@ module Somemoji
117
117
  # @return [String] a replaced result
118
118
  # @example
119
119
  # Somemoji.emoji_collection.replace_code("I :heart: Emoji") do |emoji|
120
- # %(<img alt="#{emoji.character}" class="emoji" src="/assets/emoji/#{emoji.code_points.join('-').downcase}.png">)
120
+ # %(<img alt="#{emoji.character}" class="emoji" src="/assets/emoji/#{emoji.base_path}.png">)
121
121
  # end
122
- # #=> 'I <img alt="❤" class="emoji" src="/assets/emoji/2764.png"> Emoji'
122
+ # #=> 'I <img alt="❤" class="emoji" src="/assets/emoji/unicode/2764.png"> Emoji'
123
123
  def replace_code(string, &block)
124
124
  string.gsub(code_pattern) do |matched_string|
125
125
  block.call(find_by_code(::Regexp.last_match(1)), matched_string)
@@ -1,3 +1,3 @@
1
1
  module Somemoji
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: somemoji
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura