APIDump: Added a quick-nav menu to hook descriptions.

Second part of #403.
master
madmaxoft 2013-12-27 15:36:28 +01:00
parent b99255820b
commit 9a9888a8cc
1 changed files with 22 additions and 7 deletions

View File

@ -275,7 +275,7 @@ end
local function WriteHooks(f, a_Hooks, a_UndocumentedHooks) local function WriteHooks(f, a_Hooks, a_UndocumentedHooks, a_HookNav)
f:write([[ f:write([[
<a name="hooks"><h2>Hooks</h2></a> <a name="hooks"><h2>Hooks</h2></a>
<p> <p>
@ -301,7 +301,7 @@ local function WriteHooks(f, a_Hooks, a_UndocumentedHooks)
table.insert(a_UndocumentedHooks, hook.Name); table.insert(a_UndocumentedHooks, hook.Name);
else else
f:write(" <tr>\n <td><a href=\"" .. hook.DefaultFnName .. ".html\">" .. hook.Name .. "</a></td>\n <td>" .. LinkifyString(hook.CalledWhen, hook.Name) .. "</td>\n </tr>\n"); f:write(" <tr>\n <td><a href=\"" .. hook.DefaultFnName .. ".html\">" .. hook.Name .. "</a></td>\n <td>" .. LinkifyString(hook.CalledWhen, hook.Name) .. "</td>\n </tr>\n");
WriteHtmlHook(hook); WriteHtmlHook(hook, a_HookNav);
end end
end end
f:write([[ f:write([[
@ -379,7 +379,7 @@ function DumpAPIHtml()
return; return;
end end
-- Create a class menu that will be inserted into each class file for faster navigation (#403) -- Create a class navigation menu that will be inserted into each class file for faster navigation (#403)
local ClassMenuTab = {}; local ClassMenuTab = {};
for idx, cls in ipairs(API) do for idx, cls in ipairs(API) do
table.insert(ClassMenuTab, "<a href='"); table.insert(ClassMenuTab, "<a href='");
@ -390,6 +390,17 @@ function DumpAPIHtml()
end end
local ClassMenu = table.concat(ClassMenuTab, ""); local ClassMenu = table.concat(ClassMenuTab, "");
-- Create a hook navigation menu that will be inserted into each hook file for faster navigation(#403)
local HookNavTab = {};
for idx, hook in ipairs(Hooks) do
table.insert(HookNavTab, "<a href='");
table.insert(HookNavTab, hook.DefaultFnName);
table.insert(HookNavTab, ".html'>");
table.insert(HookNavTab, (hook.Name:gsub("^HOOK_", ""))); -- remove the "HOOK_" part of the name
table.insert(HookNavTab, "</a><br />");
end
local HookNav = table.concat(HookNavTab, "");
-- Write the HTML file: -- Write the HTML file:
f:write([[<!DOCTYPE html> f:write([[<!DOCTYPE html>
<html> <html>
@ -415,7 +426,7 @@ function DumpAPIHtml()
WriteArticles(f); WriteArticles(f);
WriteClasses(f, API, ClassMenu); WriteClasses(f, API, ClassMenu);
WriteHooks(f, Hooks, UndocumentedHooks); WriteHooks(f, Hooks, UndocumentedHooks, HookNav);
-- Copy the static files to the output folder (overwrite any existing): -- Copy the static files to the output folder (overwrite any existing):
cFile:Copy(g_Plugin:GetLocalFolder() .. "/main.css", "API/main.css"); cFile:Copy(g_Plugin:GetLocalFolder() .. "/main.css", "API/main.css");
@ -1097,7 +1108,7 @@ end
function WriteHtmlHook(a_Hook) function WriteHtmlHook(a_Hook, a_HookNav)
local fnam = "API/" .. a_Hook.DefaultFnName .. ".html"; local fnam = "API/" .. a_Hook.DefaultFnName .. ".html";
local f, error = io.open(fnam, "w"); local f, error = io.open(fnam, "w");
if (f == nil) then if (f == nil) then
@ -1120,7 +1131,11 @@ function WriteHtmlHook(a_Hook)
<h1>]], a_Hook.Name, [[</h1> <h1>]], a_Hook.Name, [[</h1>
<hr /> <hr />
</header> </header>
<p> <table><tr><td style="vertical-align: top;">Quick navigation:
]]);
f:write(a_HookNav);
f:write([[
</td><td style="vertical-align: top;"><p>
]]); ]]);
f:write(LinkifyString(a_Hook.Desc, HookName)); f:write(LinkifyString(a_Hook.Desc, HookName));
f:write("</p>\n<hr /><h1>Callback function</h1>\n<p>The default name for the callback function is "); f:write("</p>\n<hr /><h1>Callback function</h1>\n<p>The default name for the callback function is ");
@ -1150,7 +1165,7 @@ function WriteHtmlHook(a_Hook)
f:write("<p>", (example.Desc or "<i>missing Desc</i>"), "</p>\n"); f:write("<p>", (example.Desc or "<i>missing Desc</i>"), "</p>\n");
f:write("<pre class=\"prettyprint lang-lua\">", (example.Code or "<i>missing Code</i>"), "\n</pre>\n\n"); f:write("<pre class=\"prettyprint lang-lua\">", (example.Code or "<i>missing Code</i>"), "\n</pre>\n\n");
end end
f:write([[</div><script>prettyPrint();</script></body></html>]]); f:write([[</td></tr></table></div><script>prettyPrint();</script></body></html>]]);
f:close(); f:close();
end end