build_emoji: Generate emoji names and codepoints from emoji_map.

Replaces the hardcoded list of emoji_names and unicode_emoji_names in
static/js/emoji.js with a list generated from emoji_map.json, both to get
the list out of version control and so we can start modifying it for our
autocomplete. This does not change the contents of emoji_names. It sorts and
removes duplicates from unicode_emoji_names (causes no change in behavior,
since unicode_emoji_names is only used as if it were a set).
This commit is contained in:
Rishi Gupta 2017-01-25 15:41:53 -08:00 committed by Tim Abbott
parent 762b84710e
commit 6b3abce541
7 changed files with 32 additions and 9 deletions

View File

@ -91,7 +91,8 @@
"pm_list": false, "pm_list": false,
"unread_ui": false, "unread_ui": false,
"user_events": false, "user_events": false,
"Plotly": false "Plotly": false,
"emoji_codes": false
}, },
"rules": { "rules": {
"no-restricted-syntax": 1, "no-restricted-syntax": 1,

View File

@ -30,6 +30,7 @@ set_global('page_params', {
add_dependencies({ add_dependencies({
marked: 'third/marked/lib/marked.js', marked: 'third/marked/lib/marked.js',
emoji_codes: 'generated/emoji/emoji_codes.js',
emoji: 'js/emoji.js', emoji: 'js/emoji.js',
people: 'js/people.js', people: 'js/people.js',
stream_data: 'js/stream_data.js', stream_data: 'js/stream_data.js',

View File

@ -6,6 +6,7 @@ set_global('page_params', {realm_emoji: {
add_dependencies({ add_dependencies({
Handlebars: 'handlebars', Handlebars: 'handlebars',
templates: 'js/templates', templates: 'js/templates',
emoji_codes: 'generated/emoji/emoji_codes.js',
emoji: 'js/emoji', emoji: 'js/emoji',
i18n: 'i18next', i18n: 'i18next',
}); });

File diff suppressed because one or more lines are too long

View File

@ -29,6 +29,21 @@ TARGET_EMOJI_DUMP = os.path.join(ZULIP_PATH, 'static', 'generated', 'emoji')
EMOJI_CACHE_PATH = "/srv/zulip-emoji-cache" EMOJI_CACHE_PATH = "/srv/zulip-emoji-cache"
EMOJI_SCRIPT_DIR_PATH = os.path.join(ZULIP_PATH, 'tools', 'setup', 'emoji') EMOJI_SCRIPT_DIR_PATH = os.path.join(ZULIP_PATH, 'tools', 'setup', 'emoji')
EMOJI_CODES_FILE_TEMPLATE = """\
var emoji_codes = (function () {
var exports = {};
exports.names = %(names)s;
exports.codepoints = %(codepoints)s;
return exports;
}());
if (typeof module !== 'undefined') {
module.exports = emoji_codes;
}
"""
# change directory # change directory
os.chdir(EMOJI_SCRIPT_DIR_PATH) os.chdir(EMOJI_SCRIPT_DIR_PATH)
@ -209,5 +224,13 @@ def dump_emojis(cache_path):
assets = "{}/static/assets/zulip-emoji/*".format(ZULIP_PATH) assets = "{}/static/assets/zulip-emoji/*".format(ZULIP_PATH)
run(['cp', '-RPp', assets, cache_emoji], shell=True) run(['cp', '-RPp', assets, cache_emoji], shell=True)
EMOJI_CODES_PATH = os.path.join(cache_path, 'emoji_codes.js')
emoji_codes_file = open(EMOJI_CODES_PATH, 'w')
emoji_codes_file.write(EMOJI_CODES_FILE_TEMPLATE % {
'names': [str(name) for name in sorted(emoji_map.keys())],
'codepoints': sorted([str(code_point) for code_point in set(emoji_map.values())])
})
emoji_codes_file.close()
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View File

@ -1,2 +1,2 @@
ZULIP_VERSION = "1.4.1+git" ZULIP_VERSION = "1.4.1+git"
PROVISION_VERSION = '4.3' PROVISION_VERSION = '4.4'

View File

@ -773,6 +773,7 @@ JS_SPECS = {
'node_modules/winchan/winchan.js', 'node_modules/winchan/winchan.js',
'third/handlebars/handlebars.runtime.js', 'third/handlebars/handlebars.runtime.js',
'third/marked/lib/marked.js', 'third/marked/lib/marked.js',
'generated/emoji/emoji_codes.js',
'templates/compiled.js', 'templates/compiled.js',
'js/feature_flags.js', 'js/feature_flags.js',
'js/loading.js', 'js/loading.js',