diff --git a/MCServer/Plugins/APIDump/main.lua b/MCServer/Plugins/APIDump/main.lua
index 1f814fc68..0ca68e107 100644
--- a/MCServer/Plugins/APIDump/main.lua
+++ b/MCServer/Plugins/APIDump/main.lua
@@ -10,6 +10,7 @@
-- Global variables:
g_Plugin = nil;
g_PluginFolder = "";
+g_TrackedPages = {}; -- List of tracked pages, to be checked later whether they exist. Each item is an array of referring pagenames.
@@ -262,7 +263,7 @@ function DumpAPIHtml()
f:write("
\n");
WriteHtmlHook(hook);
end
end
@@ -399,6 +400,9 @@ function DumpAPIHtml()
f:close();
end
+ -- List the missing pages
+ ListMissingPages();
+
LOG("API subfolder written");
end
@@ -638,7 +642,18 @@ end
-- Make a link out of anything with the special linkifying syntax {{link|title}}
-function LinkifyString(a_String)
+function LinkifyString(a_String, a_Referrer)
+ assert(a_Referrer ~= nil);
+ assert(a_Referrer ~= "");
+
+ --- 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 {});
+ table.insert(Pg, a_Referrer);
+ g_TrackedPages[a_PageName] = Pg;
+ end
+
+ --- Creates the HTML for the specified link and title
local function CreateLink(Link, Title)
if (Link:sub(1, 7) == "http://") then
-- The link is a full absolute URL, do not modify, do not track:
@@ -652,16 +667,17 @@ function LinkifyString(a_String)
return "" .. Title .. "";
end
-- Anchor in another page:
- -- TODO: track this link
- return "" .. Title .. "";
+ local PageName = Link:sub(1, idxHash - 1);
+ AddTrackedPage(PageName);
+ return "" .. Title .. "";
end
-- Link without anchor:
- -- TODO; track this link
+ AddTrackedPage(Link);
return "" .. Title .. "";
end
+ -- Linkify the strings using the CreateLink() function:
local txt = a_String:gsub("{{([^|}]*)|([^}]*)}}", CreateLink) -- {{link|title}}
-
txt = txt:gsub("{{([^|}]*)}}", -- {{LinkAndTitle}}
function(LinkAndTitle)
local idxHash = LinkAndTitle:find("#");
@@ -697,9 +713,9 @@ function WriteHtmlClass(a_ClassAPI, a_AllAPI)
cf:write("
\n
\n
Name
\n
Parameters
\n
Return value
\n
Notes
\n
\n");
for i, func in ipairs(a_Functions) do
cf:write("
\n
" .. func.Name .. "
\n");
- cf:write("
" .. LinkifyString(func.Params or "").. "
\n");
- cf:write("
" .. LinkifyString(func.Return or "").. "
\n");
- cf:write("
" .. LinkifyString(func.Notes or "") .. "
\n
\n");
+ cf:write("
" .. LinkifyString(func.Params or "", (a_InheritedName or a_ClassAPI.Name)).. "
\n");
+ cf:write("
" .. LinkifyString(func.Return or "", (a_InheritedName or a_ClassAPI.Name)).. "
\n");
+ cf:write("
" .. LinkifyString(func.Notes or "", (a_InheritedName or a_ClassAPI.Name)) .. "
\n \n");
end
cf:write("
\n\n");
end
@@ -716,6 +732,8 @@ function WriteHtmlClass(a_ClassAPI, a_AllAPI)
end
cf:write("\n");
end
+
+ local ClassName = a_ClassAPI.Name;
-- Build an array of inherited classes chain:
local InheritanceChain = {};
@@ -760,10 +778,10 @@ function WriteHtmlClass(a_ClassAPI, a_AllAPI)
cf:write(" \n\n");
-- Write the class description:
- cf:write("
\n\n");
end;
@@ -790,7 +808,7 @@ function WriteHtmlClass(a_ClassAPI, a_AllAPI)
for i, cons in ipairs(a_ClassAPI.Constants) do
cf:write("
\n
" .. cons.Name .. "
\n");
cf:write("
" .. cons.Value .. "
\n");
- cf:write("
" .. LinkifyString(cons.Notes or "") .. "
\n
\n");
+ cf:write("
" .. LinkifyString(cons.Notes or "", ClassName) .. "
\n \n");
end
cf:write(" \n\n");
@@ -805,7 +823,7 @@ function WriteHtmlClass(a_ClassAPI, a_AllAPI)
if (a_ClassAPI.AdditionalInfo ~= nil) then
for i, additional in ipairs(a_ClassAPI.AdditionalInfo) do
cf:write("
The default name for the callback function is ");
f:write(a_Hook.DefaultFnName .. ". It has the following signature:\n\n");
- f:write("
function " .. a_Hook.DefaultFnName .. "(");
+ f:write("
function " .. HookName .. "(");
if (a_Hook.Params == nil) then
a_Hook.Params = {};
end
@@ -855,7 +875,7 @@ function WriteHtmlHook(a_Hook)
end
f:write(")
\n\n
Parameters:
\n\n
\n
\n
Name
\n
Type
\n
Notes
\n
\n");
for i, param in ipairs(a_Hook.Params) do
- f:write("
\n
" .. param.Name .. "
\n
" .. LinkifyString(param.Type) .. "
\n
" .. LinkifyString(param.Notes) .. "
\n
\n");
+ f:write("
\n
" .. param.Name .. "
\n
" .. LinkifyString(param.Type, HookName) .. "
\n
" .. LinkifyString(param.Notes, HookName) .. "
\n
\n");
end
f:write("
\n\n
" .. (a_Hook.Returns or "") .. "
\n\n");
f:write([[
Code examples
@@ -880,3 +900,44 @@ end
+
+function ListMissingPages()
+ local MissingPages = {};
+ for PageName, Referrers in pairs(g_TrackedPages) do
+ if not(cFile:Exists("API/" .. PageName .. ".html")) then
+ table.insert(MissingPages, {Name = PageName, Refs = Referrers} );
+ end
+ end;
+ g_TrackedPages = {};
+
+ if (#MissingPages == 0) then
+ -- No missing pages, congratulations!
+ return;
+ end
+
+ -- Sort the pages by name:
+ table.sort(MissingPages,
+ function (Page1, Page2)
+ return (Page1.Name < Page2.Name);
+ end
+ );
+
+ -- Output the pages:
+ local f, err = io.open("API/_missingPages.txt", "w");
+ if (f == nil) then
+ LOGWARNING("Cannot open _missingPages.txt for writing: '" .. err .. "'. There are " .. #MissingPages .. " pages missing.");
+ return;
+ end
+ for idx, pg in ipairs(MissingPages) do
+ f:write(pg.Name .. ":\n");
+ -- Sort and output the referrers:
+ table.sort(pg.Refs);
+ f:write("\t" .. table.concat(pg.Refs, "\n\t"));
+ f:write("\n\n");
+ end
+ f:close();
+end
+
+
+
+