-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapi.lua
198 lines (174 loc) · 7.77 KB
/
api.lua
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
--[[
https://github.com/Gethe/wow-ui-source/tree/beta/AddOns/Blizzard_APIDocumentation
--]]
-- add functions and globals needed by addon
function Mixin(object, ...)
for i = 1, select("#", ...) do
local mixin = select(i, ...);
for k, v in pairs(mixin) do
--if k == "GenerateAPILink" then
-- object[k] = GenerateAPILink
--end
object[k] = v;
end
end
return object;
end
function CreateFromMixins(...)
return Mixin({}, ...)
end
ChatTypeInfo = {
["SYSTEM"] = {
["r"] = 1,
["b"] = 0,
["g"] = 1,
["id"] = 1,
["sticky"] = 0,
colorNameByClass = false,
flashTab = false,
flashTabOnGeneral = false
}
}
function string:split(inputstr)
if not inputstr then return nil end
local t = {}
local i = 1
for str in string.gmatch(inputstr, "([^"..self.."]+)") do
t[i] = str
i = i + 1
end
return unpack(t) -- i know wtf, but we need it for blizzard functions
end
function string:split2(inputstr)
if not inputstr then return nil end
local t = {}
local i = 1
for str in string.gmatch(inputstr, "([^"..self.."]+)") do
t[i] = str
i = i + 1
end
return t
end
unpack = table.unpack
DEFAULT_CHAT_FRAME = {} -- configure output here
function DEFAULT_CHAT_FRAME:AddMessage(message)
print(message)
end
function DEFAULT_CHAT_FRAME:SetMaxLines() end
local removelinks = true
-- with .js we can't read Blizzard_APIDocumentation.toc
local stringtocfile = [[BaseAPIMixin.lua
FieldsAPIMixin.lua
FunctionsAPIMixin.lua
SystemsAPIMixin.lua
TablesAPIMixin.lua
EventsAPIMixin.lua
Blizzard_APIDocumentation.lua]]
for _,line in pairs(("\n"):split2(stringtocfile)) do
if line then
local char1 = line:sub(1,1)
if char1 ~= "" and char1 ~= "#" then
require("Blizzard_APIDocumentation." .. line:sub(1,-5))
-- replace some mixin functions to remove links & color codes after they are loaded
-- i don't like how i do it but can't find a proper way
if removelinks then
if line == "BaseAPIMixin.lua" then
function BaseAPIMixin:GenerateAPILink()
-- return ("|cff%s|Hapi:%s:%s:%s|h%s|h|r"):format(self:GetLinkHexColor(), self:GetType(), self:GetName(), self:GetParentName(), self:GetFullName());
-- return self:GetFullName()
return ("<a class='api' style='color: #%s' href='?search=api:%s:%s:%s'>%s</a>"):format(self:GetLinkHexColor(), self:GetType(), self:GetName(), self:GetParentName(), self:GetFullName());
end
end
if line == "FieldsAPIMixin.lua" then
function FieldsAPIMixin:GetArgumentString(decorateOptionals, includeColorCodes)
--local includeColorCodes = false
local prefix = decorateOptionals ~= false and self:IsOptional() and "optional " or "";
if includeColorCodes ~= false then
return ("<span style='color: #%s'>%s%s</span>"):format(self:GetLinkHexColor(), prefix, self:GetName());
end
return ("%s%s"):format(prefix, self:GetName());
end
end
if line == "EventsAPIMixin.lua" then
function EventsAPIMixin:GetPayloadString(decorateOptionals, includeColorCodes) -- override
--local includeColorCodes = false
if self.Payload then
local values = {};
for _, payloadInfo in ipairs(self.Payload) do
if includeColorCodes ~= false then
table.insert(values, ("%s<span style='color: #%s'/>"):format(payloadInfo:GetPayloadString(decorateOptionals, includeColorCodes), self:GetLinkHexColor()));
else
table.insert(values, payloadInfo:GetPayloadString(decorateOptionals, includeColorCodes));
end
end
return table.concat(values, ", ");
end
return "";
end
end
if line == "FunctionsAPIMixin.lua" then
function FunctionsAPIMixin:GetArgumentString(decorateOptionals)
local includeColorCodes = false
if self.Arguments then
local values = {};
for _, argumentInfo in ipairs(self.Arguments) do
if includeColorCodes ~= false then
table.insert(values, ("%s|cff%s"):format(argumentInfo:GetArgumentString(decorateOptionals, includeColorCodes), self:GetLinkHexColor()));
else
table.insert(values, argumentInfo:GetArgumentString(decorateOptionals, includeColorCodes));
end
end
return table.concat(values, ", ");
end
return "";
end
function FunctionsAPIMixin:GetReturnString(decorateOptionals)
local includeColorCodes = false
if self.Returns then
local values = {};
for i, returnInfo in ipairs(self.Returns) do
if includeColorCodes ~= false then
table.insert(values, ("%s|cff%s"):format(returnInfo:GetReturnString(decorateOptionals, includeColorCodes), self:GetLinkHexColor()));
else
table.insert(values, returnInfo:GetReturnString(decorateOptionals, includeColorCodes));
end
end
return table.concat(values, ", ");
end
return "";
end
end
end
end
end
end
-- replace < > with < >
function APIDocumentation:OutputUsage()
self:WriteLine("Usage:");
self:WriteLine("Search for API");
self:WriteLine(self:GetIndentString() .. "/api search <api name>");
self:WriteLine(self:GetIndentString() .. "or");
self:WriteLine(self:GetIndentString() .. "/api s <api name>");
self:WriteLine(self:GetIndentString() .. "Example: /api search item");
self:WriteLine(" ");
self:WriteLine("List all systems");
self:WriteLine(self:GetIndentString() .. "/api system list");
self:WriteLine(" ");
self:WriteLine("Search system for API");
self:WriteLine(self:GetIndentString() .. "/api <system name> search <api name>");
self:WriteLine(self:GetIndentString() .. "or");
self:WriteLine(self:GetIndentString() .. "/api <system name> s <api name>");
self:WriteLine(self:GetIndentString() .. "Example: /api artifactui search relic");
self:WriteLine(" ");
self:WriteLine("List all API in a system");
self:WriteLine(self:GetIndentString() .. "/api <system name> list");
self:WriteLine(self:GetIndentString() .. "Example: /api artifactui list");
self:WriteLine(" ");
self:WriteLine("All searches support Lua patterns.");
end
require("fulldoc2")
if args and args:sub(1,4) == "api:" then
APIDocumentation:HandleAPILink(args, nil)
else
APIDocumentation:HandleSlashCommand(args)
end