1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 09:18:48 +02:00
phorge-phorge/scripts/celerity/generate_emoji.php
Chad Little f930fd2e00 Add an Emoji Typeahead
Summary:
This adds a more complete emoji datasource, with a typeahead and autocomplete. It works by pulling in a raw datasource from EmojiOne (I chose Unicode 8, but they have a Unicode 9 datasource as well) and transforming it for speed/need. If we build more robustness or an actual picker into the Remarkup bar, having the additional keywords, etc, might be important. When Unicode 9 support is more prevalent, we should only need to update the single file.

 Tossing up as a proof of concept on engineering direction. Also I can't quite get the autocomplete to complete.

Test Plan: Test UIExamples, Autocomplete, and TypeaheadSource

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Maniphest Tasks: T12139

Differential Revision: https://secure.phabricator.com/D17244
2017-01-24 13:13:10 -08:00

48 lines
1.2 KiB
PHP
Executable file

#!/usr/bin/env php
<?php
require_once dirname(dirname(__FILE__)).'/__init_script__.php';
$args = new PhutilArgumentParser($argv);
$args->setTagline(pht('regenerate Emoji data sheets'));
$args->setSynopsis(<<<EOHELP
**emoji**
Rebuild Emoji data sheets.
EOHELP
);
$args->parseStandardArguments();
$args->parse(
array(
array(
'name' => 'force',
'help' => pht('Force regeneration even if sources have not changed.'),
),
));
$root = dirname(phutil_get_library_root('phabricator'));
$path = $root.'/webroot/rsrc/externals/emojione/emoji_strategy.json';
$export_path = $root.'/webroot/rsrc/emoji/manifest.json';
if (Filesystem::pathExists($path)) {
$json = Filesystem::readFile($path);
$emojis = phutil_json_decode($json);
$data = array();
foreach ($emojis as $shortname => $emoji) {
$unicode = $emoji['unicode'];
$codes = explode('-', $unicode);
$hex = '';
foreach ($codes as $code) {
$hex .= phutil_utf8_encode_codepoint(hexdec($code));
}
$data[$shortname] = $hex;
}
$json = new PhutilJSON();
$data = $json->encodeFormatted($data);
Filesystem::writeFile($export_path, $data);
echo pht('Done.')."\n";
} else {
echo pht('Path %s not exist.', $path)."\n";
}