gemojione 4.1.0 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,11 +6,11 @@ require 'gemojione/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "gemojione"
8
8
  spec.version = Gemojione::VERSION
9
- spec.authors = ["Steve Klabnik", "Winfield Peterson", "Jonathan Wiesel"]
10
- spec.email = ["steve@steveklabnik.com", "winfield.peterson@gmail.com", "jonathanwiesel@gmail.com"]
9
+ spec.authors = ["Steve Klabnik", "Winfield Peterson", "Jonathan Wiesel", "Allan McLelland"]
10
+ spec.email = ["steve@steveklabnik.com", "winfield.peterson@gmail.com", "jonathanwiesel@gmail.com", "allan@bonus.ly"]
11
11
  spec.description = %q{A gem for EmojiOne}
12
12
  spec.summary = %q{A gem for EmojiOne}
13
- spec.homepage = "http://github.com/jonathanwiesel/gemojione"
13
+ spec.homepage = "https://github.com/bonusly/gemojione"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
@@ -9,6 +9,8 @@ rescue LoadError
9
9
  end
10
10
 
11
11
  require 'gemojione/index'
12
+ require 'gemojione/categories'
13
+ # require 'gemojione/index_importer'
12
14
 
13
15
  require 'gemojione/railtie' if defined?(Rails::Railtie)
14
16
 
@@ -73,11 +75,20 @@ module Gemojione
73
75
  end
74
76
 
75
77
  def self.image_tag_for_moji(moji)
78
+ emoji = index.find_by_moji(moji)
76
79
  if use_sprite
77
- emoji = index.find_by_moji(moji)
78
80
  %Q{<span class="emojione emojione-#{emoji['unicode'].to_s.downcase}" alt="#{ emoji['name'] }" title="#{ emoji['shortname'] }">#{ moji }</span>}
79
81
  else
80
- %Q{<img alt="#{moji}" class="emoji" src="#{ image_url_for_unicode_moji(moji) }"#{ default_size ? ' style="width: '+default_size+';"' : '' }>}
82
+ %Q{<img alt="#{emoji['moji']}" class="emoji" src="#{ image_url_for_unicode_moji(moji) }"#{ default_size ? ' style="width: '+default_size+';"' : '' }>}
83
+ end
84
+ end
85
+
86
+ def self.image_tag_for_unicode(unicode)
87
+ emoji = index.find_by_unicode(unicode)
88
+ if use_sprite
89
+ %Q{<span class="emojione emojione-#{emoji['unicode'].to_s.downcase}" alt="#{ emoji['name'] }" title="#{ emoji['shortname'] }">#{ emoji['moji'] }</span>}
90
+ else
91
+ %Q{<img alt="#{emoji['name']}" class="emoji" src="#{ image_url_for_unicode_moji(emoji['moji']) }"#{ default_size ? ' style="width: '+default_size+';"' : '' }>}
81
92
  end
82
93
  end
83
94
 
@@ -105,8 +116,8 @@ module Gemojione
105
116
  safe_string = safe_string(string.dup)
106
117
  safe_string.gsub!(index.shortname_moji_regex) do |code|
107
118
  name = code.tr(':','')
108
- moji = index.find_by_name(name)['moji']
109
- Gemojione.image_tag_for_moji(moji)
119
+ moji = index.find_by_name(name)
120
+ Gemojione.image_tag_for_unicode(moji['unicode'])
110
121
  end
111
122
  safe_string = safe_string.html_safe if safe_string.respond_to?(:html_safe)
112
123
 
@@ -132,6 +143,21 @@ module Gemojione
132
143
  safe_string
133
144
  end
134
145
 
146
+ def self.replace_unicode_moji_with_names(string)
147
+ return string unless string
148
+ unless string.match(index.unicode_moji_regex)
149
+ return safe_string(string)
150
+ end
151
+
152
+ safe_string = safe_string(string.dup)
153
+ safe_string.gsub!(index.unicode_moji_regex) do |moji|
154
+ index.find_by_moji(moji)['shortname']
155
+ end
156
+ safe_string = safe_string.html_safe if safe_string.respond_to?(:html_safe)
157
+
158
+ safe_string
159
+ end
160
+
135
161
  def self.safe_string(string)
136
162
  if string.respond_to?(:html_safe?) && string.html_safe?
137
163
  string
@@ -0,0 +1,212 @@
1
+ module Gemojione
2
+ class Categories
3
+ def self.all
4
+ new.all
5
+ end
6
+
7
+ def all
8
+ categories.each_with_object({}) do |category, hash|
9
+ hash[category.capitalize] = mojis_for_category(category)
10
+ end
11
+ end
12
+
13
+ private
14
+
15
+ def index
16
+ @index ||= Gemojione::Index.new
17
+ end
18
+
19
+ def categories
20
+ %w[people nature food activity travel objects symbols flags]
21
+ end
22
+
23
+ def mojis_for_category(category)
24
+ send(category).map do |name|
25
+ index.find_by_name(name)
26
+ end
27
+ end
28
+
29
+ def people
30
+ """
31
+ grinning smiley smile grin laughing sweat_smile joy rofl relaxed blush innocent slight_smile upside_down
32
+ wink relieved zany_face star_struck heart_eyes kissing_heart kissing kissing_smiling_eyes kissing_closed_eyes yum
33
+ stuck_out_tongue_winking_eye stuck_out_tongue_closed_eyes stuck_out_tongue money_mouth hugging nerd sunglasses
34
+ cowboy smirk unamused disappointed pensive worried face_with_raised_eyebrow face_with_monocle confused slight_frown
35
+ frowning2 persevere confounded tired_face weary triumph angry rage face_with_symbols_over_mouth
36
+ no_mouth neutral_face expressionless hushed frowning anguished open_mouth astonished dizzy_face exploding_head flushed scream
37
+ fearful cold_sweat cry disappointed_relieved drooling_face sob sweat sleepy sleeping rolling_eyes thinking
38
+ shushing_face face_with_hand_over_mouth lying_face grimacing zipper_mouth face_vomiting nauseated_face sneezing_face mask thermometer_face
39
+ head_bandage smiling_imp imp japanese_ogre japanese_goblin poop ghost skull skull_crossbones alien space_invader
40
+ robot jack_o_lantern clown smiley_cat smile_cat joy_cat heart_eyes_cat smirk_cat kissing_cat scream_cat crying_cat_face
41
+ pouting_cat open_hands raised_hands palms_up_together clap pray handshake thumbsup thumbsdown punch fist left_facing_fist
42
+ right_facing_fist fingers_crossed v metal love_you_gesture ok_hand point_left point_right point_up_2 point_down point_up
43
+ raised_hand raised_back_of_hand hand_splayed vulcan wave call_me muscle middle_finger writing_hand selfie
44
+ nail_care ring lipstick kiss lips tongue ear nose footprints eye eyes speaking_head bust_in_silhouette
45
+ busts_in_silhouette baby boy girl man woman blond-haired_woman blond-haired_man older_man older_woman
46
+ woman_wearing_turban man_wearing_turban woman_police_officer man_police_officer
47
+ woman_construction_worker construction_worker woman_guard man_guard woman_detective man_detective woman_health_worker
48
+ man_health_worker woman_farmer man_farmer woman_cook man_cook woman_student man_student woman_singer man_singer
49
+ woman_teacher man_teacher woman_factory_worker man_factory_worker woman_technologist man_technologist
50
+ woman_office_worker man_office_worker woman_mechanic man_mechanic woman_scientist man_scientist woman_artist
51
+ man_artist woman_firefighter man_firefighter woman_pilot man_pilot woman_astronaut man_astronaut woman_judge
52
+ man_judge mrs_claus santa princess prince bride_with_veil man_in_tuxedo angel pregnant_woman breast_feeding woman_bowing
53
+ man_bowing woman_tipping_hand man_tipping_hand woman_gesturing_no man_gesturing_no woman_gesturing_ok
54
+ man_gesturing_ok woman_raising_hand man_raising_hand woman_facepalming man_facepalming woman_shrugging
55
+ man_shrugging woman_pouting man_pouting woman_frowning man_frowning woman_getting_haircut man_getting_haircut
56
+ woman_getting_face_massage man_getting_face_massage man_in_business_suit_levitating dancer man_dancing women_with_bunny_ears_partying
57
+ men_with_bunny_ears_partying woman_walking man_walking woman_running man_running couple two_women_holding_hands
58
+ two_men_holding_hands couple_with_heart couple_ww couple_mm couplekiss kiss_ww kiss_mm family family_mwg family_mwgb
59
+ family_mwbb family_mwgg family_wwb family_wwg family_wwgb family_wwbb family_wwgg family_mmb family_mmg family_mmgb
60
+ family_mmbb family_mmgg family_woman_boy family_woman_girl family_woman_girl_boy family_woman_boy_boy
61
+ family_woman_girl_girl family_man_boy family_man_girl family_man_girl_boy family_man_boy_boy family_man_girl_girl
62
+ bearded_person woman_with_headscarf woman_mage man_mage woman_fairy man_fairy woman_vampire man_vampire
63
+ mermaid merman woman_elf man_elf woman_genie man_genie woman_zombie man_zombie
64
+ womans_clothes shirt jeans necktie dress bikini kimono high_heel sandal boot mans_shoe athletic_shoe womans_hat
65
+ tophat mortar_board crown helmet_with_cross school_satchel pouch purse handbag briefcase eyeglasses dark_sunglasses
66
+ closed_umbrella umbrella2 brain billed_cap scarf gloves coat socks
67
+ """.split(' ')
68
+ end
69
+
70
+ def nature
71
+ """
72
+ dog cat mouse hamster rabbit fox bear panda_face koala tiger lion_face cow pig pig_nose frog monkey_face see_no_evil
73
+ hear_no_evil speak_no_evil monkey chicken penguin bird baby_chick hatching_chick hatched_chick duck eagle owl bat wolf boar
74
+ horse unicorn bee bug butterfly snail shell beetle ant spider spider_web turtle snake lizard scorpion crab squid octopus shrimp
75
+ tropical_fish fish blowfish dolphin shark whale whale2 crocodile leopard tiger2 water_buffalo ox cow2 deer dromedary_camel camel
76
+ elephant rhino gorilla racehorse pig2 goat ram sheep dog2 poodle cat2 rooster turkey dove rabbit2 mouse2 rat chipmunk dragon
77
+ giraffe zebra hedgehog sauropod t_rex cricket dragon_face feet cactus christmas_tree evergreen_tree deciduous_tree palm_tree seedling herb shamrock four_leaf_clover
78
+ bamboo tanabata_tree leaves fallen_leaf maple_leaf mushroom ear_of_rice bouquet tulip rose wilted_rose sunflower blossom
79
+ cherry_blossom hibiscus earth_americas earth_africa earth_asia full_moon waning_gibbous_moon last_quarter_moon
80
+ waning_crescent_moon new_moon waxing_crescent_moon first_quarter_moon waxing_gibbous_moon new_moon_with_face
81
+ full_moon_with_face sun_with_face first_quarter_moon_with_face last_quarter_moon_with_face crescent_moon dizzy star star2
82
+ sparkles zap fire boom comet sunny white_sun_small_cloud partly_sunny white_sun_cloud white_sun_rain_cloud rainbow cloud
83
+ cloud_rain thunder_cloud_rain cloud_lightning cloud_snow snowman2 snowman snowflake wind_blowing_face dash cloud_tornado
84
+ fog ocean droplet sweat_drops umbrella
85
+ """.split(' ')
86
+ end
87
+
88
+ def food
89
+ """
90
+ green_apple apple pear tangerine lemon banana watermelon grapes strawberry melon cherries peach pineapple kiwi
91
+ avocado tomato eggplant cucumber carrot corn hot_pepper potato sweet_potato chestnut peanuts honey_pot croissant
92
+ bread french_bread cheese egg cooking bacon pancakes fried_shrimp poultry_leg meat_on_bone pizza hotdog hamburger
93
+ fries stuffed_flatbread taco burrito salad shallow_pan_of_food spaghetti ramen stew fish_cake sushi bento curry
94
+ rice_ball rice rice_cracker oden dango shaved_ice ice_cream icecream cake birthday custard lollipop candy
95
+ chocolate_bar popcorn doughnut cookie milk baby_bottle coffee tea sake beer beers champagne_glass wine_glass
96
+ tumbler_glass cocktail tropical_drink champagne spoon fork_and_knife fork_knife_plate dumpling fortune_cookie
97
+ takeout_box chopsticks bowl_with_spoon cup_with_straw coconut broccoli pie pretzel cut_of_meat sandwich canned_food
98
+ """.split(' ')
99
+ end
100
+
101
+ def activity
102
+ """
103
+ soccer basketball football baseball tennis volleyball rugby_football 8ball ping_pong badminton goal hockey field_hockey
104
+ cricket golf bow_and_arrow fishing_pole_and_fish boxing_glove martial_arts_uniform ice_skate ski skier snowboarder
105
+ woman_lifting_weights man_lifting_weights person_fencing women_wrestling men_wrestling woman_cartwheeling
106
+ man_cartwheeling woman_bouncing_ball man_bouncing_ball woman_playing_handball man_playing_handball woman_golfing
107
+ man_golfing woman_surfing man_surfing woman_swimming man_swimming woman_playing_water_polo
108
+ man_playing_water_polo woman_rowing_boat man_rowing_boat horse_racing woman_biking man_biking woman_mountain_biking man_mountain_biking
109
+ woman_in_steamy_room man_in_steamy_room woman_climbing man_climbing woman_in_lotus_position man_in_lotus_position
110
+ running_shirt_with_sash medal military_medal first_place second_place
111
+ third_place trophy rosette reminder_ribbon ticket tickets circus_tent woman_juggling man_juggling performing_arts art
112
+ clapper microphone headphones musical_score musical_keyboard drum saxophone trumpet guitar violin game_die dart bowling
113
+ video_game slot_machine sled curling_stone
114
+ """.split(' ')
115
+ end
116
+
117
+ def travel
118
+ """
119
+ red_car taxi blue_car bus trolleybus race_car police_car ambulance fire_engine minibus truck articulated_lorry tractor
120
+ scooter bike motor_scooter motorcycle rotating_light oncoming_police_car oncoming_bus oncoming_automobile oncoming_taxi
121
+ aerial_tramway mountain_cableway suspension_railway railway_car train mountain_railway monorail bullettrain_side
122
+ bullettrain_front light_rail steam_locomotive train2 metro tram station helicopter airplane_small airplane
123
+ airplane_departure airplane_arriving rocket satellite_orbital seat canoe sailboat motorboat speedboat cruise_ship
124
+ ferry ship anchor construction fuelpump busstop vertical_traffic_light traffic_light map moyai statue_of_liberty
125
+ fountain tokyo_tower european_castle japanese_castle stadium ferris_wheel roller_coaster carousel_horse beach_umbrella
126
+ beach island mountain mountain_snow mount_fuji volcano desert camping tent railway_track motorway construction_site
127
+ factory house house_with_garden homes house_abandoned office department_store post_office european_post_office hospital
128
+ bank hotel convenience_store school love_hotel wedding classical_building church mosque synagogue kaaba shinto_shrine
129
+ japan rice_scene park sunrise sunrise_over_mountains stars sparkler fireworks city_sunset city_dusk cityscape
130
+ night_with_stars milky_way bridge_at_night foggy flying_saucer
131
+ """.split(' ')
132
+ end
133
+
134
+ def objects
135
+ """
136
+ watch iphone calling computer keyboard desktop printer mouse_three_button trackball joystick compression minidisc
137
+ floppy_disk cd dvd vhs camera camera_with_flash video_camera movie_camera projector film_frames telephone_receiver
138
+ telephone pager fax tv radio microphone2 level_slider control_knobs stopwatch timer alarm_clock clock hourglass
139
+ hourglass_flowing_sand satellite battery electric_plug bulb flashlight candle wastebasket oil money_with_wings
140
+ dollar yen euro pound moneybag credit_card gem scales wrench hammer hammer_pick tools pick nut_and_bolt gear
141
+ chains gun bomb knife dagger crossed_swords shield smoking coffin urn amphora crystal_ball prayer_beads barber
142
+ alembic telescope microscope hole pill syringe thermometer toilet potable_water shower bathtub bath bellhop key
143
+ key2 door couch bed sleeping_accommodation frame_photo shopping_bags shopping_cart gift balloon flags ribbon
144
+ confetti_ball tada dolls izakaya_lantern wind_chime envelope envelope_with_arrow incoming_envelope e-mail
145
+ love_letter inbox_tray outbox_tray package label mailbox_closed mailbox mailbox_with_mail mailbox_with_no_mail
146
+ postbox postal_horn scroll page_with_curl page_facing_up bookmark_tabs bar_chart chart_with_upwards_trend
147
+ chart_with_downwards_trend notepad_spiral calendar_spiral calendar date card_index card_box ballot_box
148
+ file_cabinet clipboard file_folder open_file_folder dividers newspaper2 newspaper notebook
149
+ notebook_with_decorative_cover ledger closed_book green_book blue_book orange_book books book bookmark link
150
+ paperclip paperclips triangular_ruler straight_ruler pushpin round_pushpin scissors pen_ballpoint pen_fountain
151
+ black_nib paintbrush crayon pencil pencil2 mag mag_right lock_with_ink_pen closed_lock_with_key lock unlock
152
+ """.split(' ')
153
+ end
154
+
155
+ def symbols
156
+ """
157
+ heart orange_heart yellow_heart green_heart blue_heart purple_heart black_heart broken_heart heart_exclamation two_hearts
158
+ revolving_hearts heartbeat heartpulse sparkling_heart cupid gift_heart heart_decoration peace cross star_and_crescent
159
+ om_symbol wheel_of_dharma star_of_david six_pointed_star menorah yin_yang orthodox_cross place_of_worship ophiuchus
160
+ aries taurus gemini cancer leo virgo libra scorpius sagittarius capricorn aquarius pisces id atom accept radioactive
161
+ biohazard mobile_phone_off vibration_mode u6709 u7121 u7533 u55b6 u6708 eight_pointed_black_star vs white_flower
162
+ ideograph_advantage secret congratulations u5408 u6e80 u5272 u7981 a b ab cl o2 sos x o octagonal_sign no_entry
163
+ name_badge no_entry_sign 100 anger hotsprings no_pedestrians do_not_litter no_bicycles non-potable_water underage
164
+ no_mobile_phones no_smoking exclamation grey_exclamation question grey_question bangbang interrobang low_brightness
165
+ high_brightness part_alternation_mark warning children_crossing trident fleur-de-lis beginner recycle
166
+ white_check_mark u6307 chart sparkle eight_spoked_asterisk negative_squared_cross_mark globe_with_meridians
167
+ diamond_shape_with_a_dot_inside m cyclone zzz atm wc wheelchair parking u7a7a sa passport_control customs
168
+ baggage_claim left_luggage mens womens baby_symbol restroom put_litter_in_its_place cinema signal_strength koko
169
+ symbols information_source abc abcd capital_abcd ng ok up cool new free zero one two three four five six seven
170
+ eight nine keycap_ten 1234 hash asterisk arrow_forward pause_button play_pause stop_button record_button eject
171
+ track_next track_previous fast_forward rewind arrow_double_up arrow_double_down arrow_backward arrow_up_small
172
+ arrow_down_small arrow_right arrow_left arrow_up arrow_down arrow_upper_right arrow_lower_right arrow_lower_left
173
+ arrow_upper_left arrow_up_down left_right_arrow arrow_right_hook leftwards_arrow_with_hook arrow_heading_up
174
+ arrow_heading_down twisted_rightwards_arrows repeat repeat_one arrows_counterclockwise arrows_clockwise
175
+ musical_note notes heavy_plus_sign heavy_minus_sign heavy_division_sign heavy_multiplication_x heavy_dollar_sign
176
+ currency_exchange tm copyright registered wavy_dash curly_loop loop end back on top soon heavy_check_mark
177
+ ballot_box_with_check radio_button white_circle black_circle red_circle blue_circle small_red_triangle
178
+ small_red_triangle_down small_orange_diamond small_blue_diamond large_orange_diamond large_blue_diamond
179
+ white_square_button black_square_button black_small_square white_small_square black_medium_small_square
180
+ white_medium_small_square black_medium_square white_medium_square black_large_square white_large_square speaker
181
+ mute sound loud_sound bell no_bell mega loudspeaker speech_left eye_in_speech_bubble speech_balloon thought_balloon
182
+ anger_right spades clubs hearts diamonds black_joker flower_playing_cards mahjong clock1 clock2 clock3 clock4 clock5
183
+ clock6 clock7 clock8 clock9 clock10 clock11 clock12 clock130 clock230 clock330 clock430 clock530 clock630
184
+ clock730 clock830 clock930 clock1030 clock1130 clock1230
185
+ """.split(' ')
186
+ end
187
+
188
+ def flags
189
+ """
190
+ flag_white flag_black checkered_flag triangular_flag_on_post rainbow_flag flag_af flag_ax flag_al flag_dz flag_as
191
+ flag_ad flag_ao flag_ai flag_aq flag_ag flag_ar flag_am flag_aw flag_au flag_at flag_az flag_bs flag_bh flag_bd flag_bb
192
+ flag_by flag_be flag_bz flag_bj flag_bm flag_bt flag_bo flag_ba flag_bw flag_br flag_io flag_vg flag_bn flag_bg flag_bf
193
+ flag_bi flag_kh flag_cm flag_ca flag_ic flag_cv flag_bq flag_ky flag_cf flag_td flag_cl flag_cn flag_cx flag_cc flag_co
194
+ flag_km flag_cg flag_cd flag_ck flag_cr flag_ci flag_hr flag_cu flag_cw flag_cy flag_cz flag_dk flag_dj flag_dm flag_do
195
+ flag_ec flag_eg flag_sv flag_gq flag_er flag_ee flag_et flag_eu flag_fk flag_fo flag_fj flag_fi flag_fr flag_gf flag_pf
196
+ flag_tf flag_ga flag_gm flag_ge flag_de flag_gh flag_gi flag_gr flag_gl flag_gd flag_gp flag_gu flag_gt flag_gg flag_gn
197
+ flag_gw flag_gy flag_ht flag_hn flag_hk flag_hu flag_is flag_in flag_id flag_ir flag_iq flag_ie flag_im flag_il flag_it
198
+ flag_jm flag_jp crossed_flags flag_je flag_jo flag_kz flag_ke flag_ki flag_xk flag_kw flag_kg flag_la flag_lv flag_lb
199
+ flag_ls flag_lr flag_ly flag_li flag_lt flag_lu flag_mo flag_mk flag_mg flag_mw flag_my flag_mv flag_ml flag_mt flag_mh
200
+ flag_mq flag_mr flag_mu flag_yt flag_mx flag_fm flag_md flag_mc flag_mn flag_me flag_ms flag_ma flag_mz flag_mm flag_na
201
+ flag_nr flag_np flag_nl flag_nc flag_nz flag_ni flag_ne flag_ng flag_nu flag_nf flag_kp flag_mp flag_no flag_om flag_pk
202
+ flag_pw flag_ps flag_pa flag_pg flag_py flag_pe flag_ph flag_pn flag_pl flag_pt flag_pr flag_qa flag_re flag_ro flag_ru
203
+ flag_rw flag_ws flag_sm flag_st flag_sa flag_sn flag_rs flag_sc flag_sl flag_sg flag_sx flag_sk flag_si flag_gs flag_sb
204
+ flag_so flag_za flag_kr flag_ss flag_es flag_lk flag_bl flag_sh flag_kn flag_lc flag_pm flag_vc flag_sd flag_sr flag_sz
205
+ flag_se flag_ch flag_sy flag_tw flag_tj flag_tz flag_th flag_tl flag_tg flag_tk flag_to flag_tt flag_tn flag_tr flag_tm
206
+ flag_tc flag_tv flag_vi flag_ug flag_ua flag_ae flag_gb flag_us flag_uy flag_uz flag_vu flag_va flag_ve flag_vn flag_wf
207
+ flag_eh flag_ye flag_zm flag_zw flag_ac flag_ta flag_bv flag_hm flag_sj flag_um flag_ea flag_cp flag_dg flag_mf
208
+ united_nations england scotland wales
209
+ """.split(' ')
210
+ end
211
+ end
212
+ end
@@ -14,6 +14,7 @@ module Gemojione
14
14
  @emoji_by_code = {}
15
15
  @emoji_by_keyword = {}
16
16
  @emoji_by_category = {}
17
+ @emoji_by_unicode = {}
17
18
  @all = emoji_list
18
19
 
19
20
  emoji_list.each do |key, emoji_hash|
@@ -38,6 +39,9 @@ module Gemojione
38
39
  moji = emoji_hash['moji']
39
40
  @emoji_by_moji[moji] = emoji_hash if moji
40
41
 
42
+ unicode = emoji_hash['unicode']
43
+ @emoji_by_unicode[unicode] = emoji_hash if unicode
44
+
41
45
  emoji_hash['keywords'].each do |emoji_keyword|
42
46
  @emoji_by_keyword[emoji_keyword] ||= []
43
47
  @emoji_by_keyword[emoji_keyword] << emoji_hash
@@ -51,7 +55,7 @@ module Gemojione
51
55
  end
52
56
 
53
57
  @emoji_code_regex = /#{@emoji_by_code.keys.map{|ec| Regexp.escape(ec)}.join('|')}/
54
- @emoji_moji_regex = /#{@emoji_by_moji.keys.map{|ec| Regexp.escape(ec)}.join('|')}/
58
+ @emoji_moji_regex = /#{@emoji_by_moji.keys.sort { |a, b| b.length <=> a.length }.map{|ec| Regexp.escape(ec)}.join('|')}/
55
59
  @emoji_ascii_regex = /#{@emoji_by_ascii.keys.map{|ec| Regexp.escape(ec)}.join('|')}/
56
60
  end
57
61
 
@@ -79,6 +83,10 @@ module Gemojione
79
83
  @emoji_by_code[shortname]
80
84
  end
81
85
 
86
+ def find_by_unicode(unicode)
87
+ @emoji_by_unicode[unicode]
88
+ end
89
+
82
90
  def unicode_moji_regex
83
91
  @emoji_moji_regex
84
92
  end
@@ -0,0 +1,94 @@
1
+ class IndexImporter
2
+ SOURCE = 'https://raw.githubusercontent.com/joypixels/emojione/master/emoji.json'
3
+
4
+ def self.import_from_emojione
5
+ new.import_from_emojione
6
+ end
7
+
8
+ def import_from_emojione
9
+ count = 0
10
+
11
+ mojis.each do |array|
12
+ unicode = array[0].upcase
13
+ hash = array[1]
14
+
15
+ unless index.find_by_unicode(unicode)
16
+ count += 1
17
+ add_moji(
18
+ hash['shortname'].gsub(':', ''),
19
+ unicode,
20
+ hash['name'],
21
+ hash['category'],
22
+ hash['code_points']['fully_qualified'].split('-').map { |u| u.downcase.to_i(16) }.pack('U*'),
23
+ hash['shortname_alternates']
24
+ )
25
+ end
26
+ end
27
+
28
+ puts "Added #{count} emojis to the index"
29
+ end
30
+
31
+ private
32
+
33
+ def mojis
34
+ @mojis ||= JSON.parse(HTTParty.get(SOURCE).body)
35
+ end
36
+
37
+ def index
38
+ @index ||= Gemojione::Index.new
39
+ end
40
+
41
+ def add_moji(name, unicode, description, category, moji, aliases)
42
+ file = File.absolute_path(File.dirname(__FILE__) + '/../../config/index.json')
43
+ emoji_list ||= begin
44
+ emoji_json = File.read(file)
45
+ JSON.parse(emoji_json)
46
+ end
47
+
48
+ emoji_list[name] = {
49
+ 'unicode' => unicode,
50
+ 'name' => description,
51
+ 'shortname' => ":#{name}:",
52
+ 'category' => category,
53
+ 'moji' => moji,
54
+ 'unicode_alternates' => [],
55
+ 'aliases' => aliases,
56
+ 'aliases_ascii' => [],
57
+ 'keywords' => []
58
+ }
59
+
60
+ File.open(file, 'w') do |f|
61
+ f.write(JSON.pretty_generate(emoji_list))
62
+ end
63
+ end
64
+
65
+ def self.prettyify_index
66
+ file = File.absolute_path(File.dirname(__FILE__) + '/../config/index.json')
67
+ emoji_list ||= begin
68
+ emoji_json = File.read(file)
69
+ JSON.parse(emoji_json)
70
+ end
71
+
72
+ File.open(file, 'w') do |f|
73
+ f.write(JSON.pretty_generate(emoji_list))
74
+ end
75
+ end
76
+
77
+ def self.add_alias(moji, new_alias)
78
+ file = File.absolute_path(File.dirname(__FILE__) + '/../config/index.json')
79
+ emoji_list ||= begin
80
+ emoji_json = File.read(file)
81
+ JSON.parse(emoji_json)
82
+ end
83
+
84
+ index = Index.new
85
+ return if index.find_by_moji(moji).nil?
86
+
87
+ name = index.find_by_moji(moji)['name']
88
+ emoji_list[name]['aliases'] << ":#{new_alias}:"
89
+
90
+ File.open(file, 'w') do |f|
91
+ f.write(JSON.pretty_generate(emoji_list))
92
+ end
93
+ end
94
+ end
@@ -1,3 +1,3 @@
1
1
  module Gemojione
2
- VERSION = "4.1.0"
2
+ VERSION = "4.2.0"
3
3
  end
@@ -95,6 +95,12 @@ describe Gemojione do
95
95
  assert_equal "I <img alt=\"❤\" class=\"emoji\" src=\"http://localhost:3000/2764.png\"> Emoji", replaced_string
96
96
  end
97
97
 
98
+ it 'should replace diversity unicode moji properly' do
99
+ base_string = "Woman elf tone5 🧝🏿‍♀️"
100
+ replaced_string = Gemojione.replace_unicode_moji_with_images(base_string)
101
+ assert_equal "Woman elf tone5 <img alt=\"🧝🏿‍♀️\" class=\"emoji\" src=\"http://localhost:3000/1f9dd-1f3ff-2640.png\">", replaced_string
102
+ end
103
+
98
104
  it 'should replace unicode moji with span tag for spritesheet' do
99
105
  with_emoji_config(:use_sprite, true) do
100
106
  base_string = "I ❤ Emoji"
@@ -177,19 +183,19 @@ describe Gemojione do
177
183
 
178
184
  it 'should escape html in non html_safe aware strings' do
179
185
  replaced_string = Gemojione.replace_named_moji_with_images(':heart:<script>')
180
- assert_equal "<img alt=\"❤\" class=\"emoji\" src=\"http://localhost:3000/2764.png\">&lt;script&gt;", replaced_string
186
+ assert_equal "<img alt=\"heart\" class=\"emoji\" src=\"http://localhost:3000/2764.png\">&lt;script&gt;", replaced_string
181
187
  end
182
188
 
183
189
  it 'should replace coded moji with img tag' do
184
190
  base_string = "I :heart: Emoji"
185
191
  replaced_string = Gemojione.replace_named_moji_with_images(base_string)
186
- assert_equal "I <img alt=\"❤\" class=\"emoji\" src=\"http://localhost:3000/2764.png\"> Emoji", replaced_string
192
+ assert_equal "I <img alt=\"heart\" class=\"emoji\" src=\"http://localhost:3000/2764.png\"> Emoji", replaced_string
187
193
  end
188
194
 
189
195
  it 'should replace aliased moji with img tag' do
190
196
  base_string = "Good one :+1:"
191
197
  replaced_string = Gemojione.replace_named_moji_with_images(base_string)
192
- assert_equal "Good one <img alt=\"👍\" class=\"emoji\" src=\"http://localhost:3000/1f44d.png\">", replaced_string
198
+ assert_equal "Good one <img alt=\"thumbsup\" class=\"emoji\" src=\"http://localhost:3000/1f44d.png\">", replaced_string
193
199
  end
194
200
 
195
201
  it 'should handle nil string' do
@@ -204,7 +210,7 @@ describe Gemojione do
204
210
  Gemojione.replace_named_moji_with_images(string)
205
211
  end
206
212
 
207
- assert_equal "<img alt=\"❤\" class=\"emoji\" src=\"http://localhost:3000/2764.png\">&lt;script&gt;", replaced_string
213
+ assert_equal "<img alt=\"heart\" class=\"emoji\" src=\"http://localhost:3000/2764.png\">&lt;script&gt;", replaced_string
208
214
  end
209
215
 
210
216
  it 'should escape non html_safe? strings in all strings' do
@@ -224,7 +230,7 @@ describe Gemojione do
224
230
  Gemojione.replace_named_moji_with_images(string)
225
231
  end
226
232
 
227
- assert_equal "<img alt=\"❤\" class=\"emoji\" src=\"http://localhost:3000/2764.png\"><a href=\"harmless\">", replaced_string
233
+ assert_equal "<img alt=\"heart\" class=\"emoji\" src=\"http://localhost:3000/2764.png\"><a href=\"harmless\">", replaced_string
228
234
  end
229
235
 
230
236
  it 'should always return an html_safe string for emoji' do
@@ -271,6 +277,18 @@ describe Gemojione do
271
277
  end
272
278
  end
273
279
 
280
+ describe "replace_unicode_moji_with_names" do
281
+ it 'should replace unicode mojis with their shortnames' do
282
+ replaced_string = Gemojione.replace_unicode_moji_with_names("Emoji is 😄")
283
+ assert_equal "Emoji is :smile:", replaced_string
284
+ end
285
+
286
+ it 'replaces diversity mojis with their shortnames properly' do
287
+ replaced_string = Gemojione.replace_unicode_moji_with_names("Emoji is 🧝🏿‍♀️")
288
+ assert_equal "Emoji is :woman_elf_tone5:", replaced_string
289
+ end
290
+ end
291
+
274
292
  describe "images_path" do
275
293
  it "should always return a valid default path" do
276
294
  path = Gemojione.images_path