negarmoji 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,100 @@
1
+ negarmoji
2
+ ======
3
+
4
+ This library contains character information about native emojis.
5
+
6
+
7
+ Installation
8
+ ------------
9
+
10
+ Add `negarmoji` to your Gemfile.
11
+
12
+ ``` ruby
13
+ gem 'negarmoji'
14
+ ```
15
+
16
+
17
+ Example Rails Helper
18
+ --------------------
19
+
20
+ This would allow emojifying content such as: `it's raining :cat:s and :dog:s!`
21
+
22
+ See the [Emoji cheat sheet](http://www.emoji-cheat-sheet.com) for more examples.
23
+
24
+ ```ruby
25
+ module EmojiHelper
26
+ def emojify(content)
27
+ h(content).to_str.gsub(/:([\w+-]+):/) do |match|
28
+ if emoji = Emoji.find_by_alias($1)
29
+ %(<img alt="#$1" src="#{image_path("emoji/#{emoji.image_filename}")}" style="vertical-align:middle" width="20" height="20" />)
30
+ else
31
+ match
32
+ end
33
+ end.html_safe if content.present?
34
+ end
35
+ end
36
+ ```
37
+
38
+ Unicode mapping
39
+ ---------------
40
+
41
+ Translate emoji names to unicode and vice versa.
42
+
43
+ ```ruby
44
+ >> Emoji.find_by_alias("cat").raw
45
+ => "🐱" # Don't see a cat? That's U+1F431.
46
+
47
+ >> Emoji.find_by_unicode("\u{1f431}").name
48
+ => "cat"
49
+ ```
50
+
51
+ Adding new emoji
52
+ ----------------
53
+
54
+ You can add new emoji characters to the `Emoji.all` list:
55
+
56
+ ```ruby
57
+ emoji = Emoji.create("music") do |char|
58
+ char.add_alias "song"
59
+ char.add_unicode_alias "\u{266b}"
60
+ char.add_tag "notes"
61
+ end
62
+
63
+ emoji.name #=> "music"
64
+ emoji.raw #=> "♫"
65
+ emoji.image_filename #=> "unicode/266b.png"
66
+
67
+ # Creating custom emoji (no Unicode aliases):
68
+ emoji = Emoji.create("music") do |char|
69
+ char.add_tag "notes"
70
+ end
71
+
72
+ emoji.custom? #=> true
73
+ emoji.image_filename #=> "music.png"
74
+ ```
75
+
76
+ As you create new emoji, you must ensure that you also create and put the images
77
+ they reference by their `image_filename` to your assets directory.
78
+
79
+ You can customize `image_filename` with:
80
+
81
+ ```ruby
82
+ emoji = Emoji.create("music") do |char|
83
+ char.image_filename = "subdirectory/my_emoji.gif"
84
+ end
85
+ ```
86
+
87
+ For existing emojis, you can edit the list of aliases or add new tags in an edit block:
88
+
89
+ ```ruby
90
+ emoji = Emoji.find_by_alias "musical_note"
91
+
92
+ Emoji.edit_emoji(emoji) do |char|
93
+ char.add_alias "music"
94
+ char.add_unicode_alias "\u{266b}"
95
+ char.add_tag "notes"
96
+ end
97
+
98
+ Emoji.find_by_alias "music" #=> emoji
99
+ Emoji.find_by_unicode "\u{266b}" #=> emoji
100
+ ```