diff options
Diffstat (limited to 'Server/Plugins/APIDump')
-rw-r--r-- | Server/Plugins/APIDump/main_APIDump.lua | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/Server/Plugins/APIDump/main_APIDump.lua b/Server/Plugins/APIDump/main_APIDump.lua index 2c88846e7..0f1476ef7 100644 --- a/Server/Plugins/APIDump/main_APIDump.lua +++ b/Server/Plugins/APIDump/main_APIDump.lua @@ -206,10 +206,15 @@ end -- Make a link out of anything with the special linkifying syntax {{link|title}} -local function LinkifyString(a_String, a_Referrer) +local function LinkifyString(a_String, a_Referrer, a_API) assert(a_Referrer ~= nil); assert(a_Referrer ~= ""); + -- If the string is a known class, return a direct link to it: + if (a_API[a_String]) then + return "<a href=\"" .. a_String .. ".html\">" .. a_String .. "</a>" + end + --- Adds a page to the list of tracked pages (to be checked for existence at the end) local function AddTrackedPage(a_PageName) local Pg = (g_TrackedPages[a_PageName] or {}); @@ -259,7 +264,7 @@ end -local function WriteHtmlHook(a_Hook, a_HookNav) +local function WriteHtmlHook(a_Hook, a_HookNav, a_API) local fnam = "API/" .. a_Hook.DefaultFnName .. ".html"; local f, error = io.open(fnam, "w"); if (f == nil) then @@ -295,7 +300,7 @@ local function WriteHtmlHook(a_Hook, 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, a_API)); f:write("</p>\n<hr /><h1>Callback function</h1>\n<p>The default name for the callback function is "); f:write(a_Hook.DefaultFnName, ". It has the following signature:\n"); f:write("<pre class=\"prettyprint lang-lua\">function My", HookName, "("); @@ -310,9 +315,9 @@ local function WriteHtmlHook(a_Hook, a_HookNav) end f:write(")</pre>\n<hr /><h1>Parameters:</h1>\n<table><tr><th>Name</th><th>Type</th><th>Notes</th></tr>\n"); for _, param in ipairs(a_Hook.Params) do - f:write("<tr><td>", param.Name, "</td><td>", LinkifyString(param.Type, HookName), "</td><td>", LinkifyString(param.Notes, HookName), "</td></tr>\n"); + f:write("<tr><td>", param.Name, "</td><td>", LinkifyString(param.Type, HookName, a_API), "</td><td>", LinkifyString(param.Notes, HookName, a_API), "</td></tr>\n"); end - f:write("</table>\n<p>" .. LinkifyString(a_Hook.Returns or "", HookName) .. "</p>\n\n"); + f:write("</table>\n<p>" .. LinkifyString(a_Hook.Returns or "", HookName, a_API) .. "</p>\n\n"); f:write([[<hr /><h1>Code examples</h1><h2>Registering the callback</h2>]]); f:write("<pre class=\"prettyprint lang-lua\">\n"); f:write([[cPluginManager:AddHook(cPluginManager.]] .. a_Hook.Name .. ", My" .. a_Hook.DefaultFnName .. [[);]]); @@ -354,7 +359,7 @@ end -- a_Hooks is an array of hook descriptions -- a_UndocumentedHooks is a table that will be filled with the names of hooks that are not documented -- a_HookNav is the HTML code for the menu on the left that is constant for all hook pages -local function WriteHooks(f, a_Hooks, a_UndocumentedHooks, a_HookNav) +local function WriteHooks(f, a_Hooks, a_UndocumentedHooks, a_HookNav, a_API) f:write([[ <a name="hooks"><h2>Hooks</h2></a> <p> @@ -379,8 +384,8 @@ local function WriteHooks(f, a_Hooks, a_UndocumentedHooks, a_HookNav) f:write(" <tr>\n <td>" .. hook.Name .. "</td>\n <td><i>(No documentation yet)</i></td>\n </tr>\n"); table.insert(a_UndocumentedHooks, hook.Name); 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"); - WriteHtmlHook(hook, a_HookNav); + f:write(" <tr>\n <td><a href=\"" .. hook.DefaultFnName .. ".html\">" .. hook.Name .. "</a></td>\n <td>" .. LinkifyString(hook.CalledWhen, hook.Name, a_API) .. "</td>\n </tr>\n"); + WriteHtmlHook(hook, a_HookNav, a_API); end end f:write([[ @@ -814,7 +819,7 @@ local function CreateFunctionParamsDescription(a_FnParams, a_ClassName, a_API) -- If the params description is a string (old format), just linkify it: if (pt == "string") then - return LinkifyString(a_FnParams, a_ClassName) + return LinkifyString(a_FnParams, a_ClassName, a_API) end -- If the params description is an empty table, give no description at all: @@ -881,7 +886,7 @@ local function WriteHtmlClass(a_ClassAPI, a_ClassMenu, a_API) cf:write("<tr><td id=\"", func.Name, "_", TableOverloadedFunctions[func.Name], "\" title=\"", func.Name, "_", TableOverloadedFunctions[func.Name], "\">", func.Name, "</td>\n"); cf:write("<td>", CreateFunctionParamsDescription(func.Params or {}, a_InheritedName or a_ClassAPI.Name, a_API), "</td>\n"); cf:write("<td>", CreateFunctionParamsDescription(func.Returns or {}, a_InheritedName or a_ClassAPI.Name, a_API), "</td>\n"); - cf:write("<td>", StaticClause .. LinkifyString(func.Notes or "<i>(undocumented)</i>", (a_InheritedName or a_ClassAPI.Name)), "</td></tr>\n"); + cf:write("<td>", StaticClause .. LinkifyString(func.Notes or "<i>(undocumented)</i>", (a_InheritedName or a_ClassAPI.Name), a_API), "</td></tr>\n"); end cf:write("</table>\n"); end @@ -891,7 +896,7 @@ local function WriteHtmlClass(a_ClassAPI, a_ClassMenu, a_API) for _, cons in ipairs(a_Constants) do cf:write("<tr><td id=\"", cons.Name, "\">", cons.Name, "</td>\n"); cf:write("<td>", cons.Value, "</td>\n"); - cf:write("<td>", LinkifyString(cons.Notes or "", a_Source), "</td></tr>\n"); + cf:write("<td>", LinkifyString(cons.Notes or "", a_Source, a_API), "</td></tr>\n"); end cf:write("</table>\n\n"); end @@ -914,9 +919,9 @@ local function WriteHtmlClass(a_ClassAPI, a_ClassMenu, a_API) for _, group in pairs(a_ConstantGroups) do if ((a_InheritedName == nil) or group.ShowInDescendants) then cf:write("<a name='", group.Name, "'><p>"); - cf:write(LinkifyString(group.TextBefore or "", Source)); + cf:write(LinkifyString(group.TextBefore or "", Source, a_API)); WriteConstantTable(group.Constants, a_InheritedName or a_ClassAPI.Name); - cf:write(LinkifyString(group.TextAfter or "", Source), "</a></p><hr/>"); + cf:write(LinkifyString(group.TextAfter or "", Source, a_API), "</a></p><hr/>"); end end end @@ -933,8 +938,8 @@ local function WriteHtmlClass(a_ClassAPI, a_ClassMenu, a_API) cf:write("<table><tr><th>Name</th><th>Type</th><th>Notes</th></tr>\n"); for _, var in ipairs(a_Variables) do cf:write("<tr><td id=\"", var.Name, "\">", var.Name, "</td>\n"); - cf:write("<td>", LinkifyString(var.Type or "<i>(undocumented)</i>", a_InheritedName or a_ClassAPI.Name), "</td>\n"); - cf:write("<td>", LinkifyString(var.Notes or "", a_InheritedName or a_ClassAPI.Name), "</td>\n </tr>\n"); + cf:write("<td>", LinkifyString(var.Type or "<i>(undocumented)</i>", a_InheritedName or a_ClassAPI.Name, a_API), "</td>\n"); + cf:write("<td>", LinkifyString(var.Notes or "", a_InheritedName or a_ClassAPI.Name, a_API), "</td>\n </tr>\n"); end cf:write("</table>\n\n"); end @@ -1026,7 +1031,7 @@ local function WriteHtmlClass(a_ClassAPI, a_ClassMenu, a_API) cf:write("<hr /><a name=\"desc\"><h1>", ClassName, " class</h1></a>\n"); if (a_ClassAPI.Desc ~= nil) then cf:write("<p>"); - cf:write(LinkifyString(a_ClassAPI.Desc, ClassName)); + cf:write(LinkifyString(a_ClassAPI.Desc, ClassName, a_API)); cf:write("</p>\n\n"); end; @@ -1081,7 +1086,7 @@ local function WriteHtmlClass(a_ClassAPI, a_ClassMenu, a_API) if (a_ClassAPI.AdditionalInfo ~= nil) then for i, additional in ipairs(a_ClassAPI.AdditionalInfo) do cf:write("<a name=\"additionalinfo_", i, "\"><h1>", additional.Header, "</h1></a>\n"); - cf:write(LinkifyString(additional.Contents, ClassName)); + cf:write(LinkifyString(additional.Contents, ClassName, a_API)); end end @@ -1464,7 +1469,7 @@ local function DumpAPIHtml(a_API, a_Descs) WriteArticles(f, a_Descs); WriteClasses(f, a_API, ClassMenu); - WriteHooks(f, Hooks, UndocumentedHooks, HookNav); + WriteHooks(f, Hooks, UndocumentedHooks, HookNav, a_API); -- Copy the static files to the output folder: local StaticFiles = |