-
Notifications
You must be signed in to change notification settings - Fork 11
/
wxapp.py
85 lines (64 loc) · 2.37 KB
/
wxapp.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import sublime
import sublime_plugin
import os
import copy
import json
# ----------------------------------------------------------
# Config
# ----------------------------------------------------------
def get_api_url():
return r'https://mp.weixin.qq.com/debug/wxadoc/dev/api/'
def get_component_url():
return r'https://mp.weixin.qq.com/debug/wxadoc/dev/component/'
def get_api_json_path():
return "/".join(["Packages", "wxapp", "wxapp_api.json"])
def get_component_json_path():
return "/".join(["Packages", "wxapp", "wxapp_component.json"])
# ----------------------------------------------------------
# Utils
# ----------------------------------------------------------
def open_url(url):
if sublime.platform() == 'osx':
command = 'open'
elif sublime.platform() == 'windows':
command = 'start'
elif sublime.platform() == 'linux':
command = 'lynx'
command += ' ' + str(url)
os.system(command)
# ----------------------------------------------------------
# Manager
# ----------------------------------------------------------
class WxappManager():
def open_doc(self, json_path, prefix_url):
doc_dict = json.loads(sublime.load_resource(json_path))
doc_list = list(doc_dict.keys())
doc_list = sorted(doc_list)
show_list = copy.copy(doc_list)
for i in range(len(show_list)):
api = doc_list[i]
info = doc_dict[api]
show_list[i] = '%s (%s)' % (api, info['desc'])
def on_done(index):
if index == -1: return
api = doc_list[index]
info = doc_dict[api]
url = prefix_url + info['href']
open_url(url)
window = sublime.active_window()
window.show_quick_panel(show_list, on_done)
# ----------------------------------------------------------
# Commands
# ----------------------------------------------------------
class OpenApiDocument(sublime_plugin.WindowCommand):
def run(self):
json_path = get_api_json_path()
prefix_url = get_api_url()
wmanager = WxappManager()
wmanager.open_doc(json_path, prefix_url)
class OpenComponentDocument(sublime_plugin.WindowCommand):
def run(self):
json_path = get_component_json_path()
prefix_url = get_component_url()
wmanager = WxappManager()
wmanager.open_doc(json_path, prefix_url)