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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +73 -1
- data/lib/somemoji/emoji.rb +7 -5
- data/lib/somemoji/emoji_collection.rb +4 -4
- data/lib/somemoji/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb3b0923dfa3d0f5b047e54028fc235ce6bc475a
|
4
|
+
data.tar.gz: c00021c451b2482a7c1a559b90de99747208c8d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0fb106ddabc5900bc370c61a90a2af8bd37554e380fba0e64fd333ae8069c986d27c1fe0e978e339e73021457c09a4ae60c57b93c9521844dfb0466e0f7a1127
|
7
|
+
data.tar.gz: 8efdff1491f24a93f517464eb058046813d6fb65f1914b07351f34e0e0c0bb2ed28c8fac50b9fdf7c120ad7397c8068038f691d2d0065c608a87a480802a121c
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# Somemoji
|
2
2
|
|
3
|
-
[![
|
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
|
+
```
|
data/lib/somemoji/emoji.rb
CHANGED
@@ -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
|
103
|
+
# @return [String, nil] a String representation from its code points
|
104
104
|
def character
|
105
|
-
code_points.
|
106
|
-
code_point
|
107
|
-
|
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.
|
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.
|
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)
|
data/lib/somemoji/version.rb
CHANGED