/
Emoji Code.py
67 lines (47 loc) · 1.98 KB
/
Emoji Code.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import os, sublime, sublime_plugin
def plugin_loaded():
from package_control import events
me = os.path.basename(os.path.dirname(os.path.realpath(__file__)))
if events.install(me) or events.post_upgrade(me):
build()
class BuildSnippetsCommand(sublime_plugin.TextCommand):
def run(self, edit):
build()
# Helper Functions
def write_completions(type, scope, prefix, suffix):
import json
from emojitations import emoji
completions = []
for attr, value in emoji.__dict__.items():
try:
slug = emoji.en[attr].slug.replace("_", "-")
literal = emoji.en[attr].emoji
codepoint = hex(emoji.en[attr].codepoints[0]).split("x")[1]
body = prefix + codepoint + suffix
trigger = "ji:" + slug + "\t" + literal
completions.append({"contents": body, "trigger": trigger})
except:
pass
snippets = {
"scope": scope,
"completions": completions
}
output = json.dumps(snippets, sort_keys=True, indent=True, separators=(",", ": "), ensure_ascii=False)
outputFile = os.path.join(os.path.dirname(os.path.realpath(__file__)), "snippets", "emoji-"+type+".sublime-completions")
with open(outputFile, "w", encoding="utf-8") as file:
print("Emoji Code: Creating \"%s\"" % outputFile)
file.write(output)
def build():
print("Emoji Code: Building Snippets")
make_directory()
make_completions()
def make_directory():
outpath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "snippets")
if not os.path.exists(outpath):
os.makedirs(outpath)
def make_completions():
write_completions("css", ".source.css, .source.sass", "content: '\\\\", "';")
write_completions("html", ".source.svelte, .text.html", "&#x", ";")
write_completions("javascript", ".source.js", "\\\\u", "")
write_completions("python", ".source.python", "u'\\\\U", "'")
write_completions("ruby", ".source.ruby", "\\\\u{", "}")