1
0

APIDump: Makes a list of bad links.

This fixes #219.
This commit is contained in:
madmaxoft 2013-10-18 12:30:06 +02:00
parent 5992c41501
commit 22102b4a64

View File

@ -10,6 +10,7 @@
-- Global variables: -- Global variables:
g_Plugin = nil; g_Plugin = nil;
g_PluginFolder = ""; 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(" <tr>\n <td>" .. hook.Name .. "</td>\n <td><i>(No documentation yet)</i></td>\n </tr>\n"); f:write(" <tr>\n <td>" .. hook.Name .. "</td>\n <td><i>(No documentation yet)</i></td>\n </tr>\n");
table.insert(UndocumentedHooks, hook.Name); table.insert(UndocumentedHooks, hook.Name);
else else
f:write(" <tr>\n <td><a href=\"" .. hook.DefaultFnName .. ".html\">" .. hook.Name .. "</a></td>\n <td>" .. LinkifyString(hook.CalledWhen) .. "</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);
end end
end end
@ -399,6 +400,9 @@ function DumpAPIHtml()
f:close(); f:close();
end end
-- List the missing pages
ListMissingPages();
LOG("API subfolder written"); LOG("API subfolder written");
end end
@ -638,7 +642,18 @@ end
-- Make a link out of anything with the special linkifying syntax {{link|title}} -- 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) local function CreateLink(Link, Title)
if (Link:sub(1, 7) == "http://") then if (Link:sub(1, 7) == "http://") then
-- The link is a full absolute URL, do not modify, do not track: -- The link is a full absolute URL, do not modify, do not track:
@ -652,16 +667,17 @@ function LinkifyString(a_String)
return "<a href=\"" .. Link .. "\">" .. Title .. "</a>"; return "<a href=\"" .. Link .. "\">" .. Title .. "</a>";
end end
-- Anchor in another page: -- Anchor in another page:
-- TODO: track this link local PageName = Link:sub(1, idxHash - 1);
return "<a href=\"" .. Link:sub(1, idxHash - 1) .. ".html#" .. Link:sub(idxHash + 1) .. "\">" .. Title .. "</a>"; AddTrackedPage(PageName);
return "<a href=\"" .. PageName .. ".html#" .. Link:sub(idxHash + 1) .. "\">" .. Title .. "</a>";
end end
-- Link without anchor: -- Link without anchor:
-- TODO; track this link AddTrackedPage(Link);
return "<a href=\"" .. Link .. ".html\">" .. Title .. "</a>"; return "<a href=\"" .. Link .. ".html\">" .. Title .. "</a>";
end end
-- Linkify the strings using the CreateLink() function:
local txt = a_String:gsub("{{([^|}]*)|([^}]*)}}", CreateLink) -- {{link|title}} local txt = a_String:gsub("{{([^|}]*)|([^}]*)}}", CreateLink) -- {{link|title}}
txt = txt:gsub("{{([^|}]*)}}", -- {{LinkAndTitle}} txt = txt:gsub("{{([^|}]*)}}", -- {{LinkAndTitle}}
function(LinkAndTitle) function(LinkAndTitle)
local idxHash = LinkAndTitle:find("#"); local idxHash = LinkAndTitle:find("#");
@ -697,9 +713,9 @@ function WriteHtmlClass(a_ClassAPI, a_AllAPI)
cf:write(" <table>\n <tr>\n <th>Name</th>\n <th>Parameters</th>\n <th>Return value</th>\n <th>Notes</th>\n </tr>\n"); cf:write(" <table>\n <tr>\n <th>Name</th>\n <th>Parameters</th>\n <th>Return value</th>\n <th>Notes</th>\n </tr>\n");
for i, func in ipairs(a_Functions) do for i, func in ipairs(a_Functions) do
cf:write(" <tr>\n <td>" .. func.Name .. "</td>\n"); cf:write(" <tr>\n <td>" .. func.Name .. "</td>\n");
cf:write(" <td>" .. LinkifyString(func.Params or "").. "</td>\n"); cf:write(" <td>" .. LinkifyString(func.Params or "", (a_InheritedName or a_ClassAPI.Name)).. "</td>\n");
cf:write(" <td>" .. LinkifyString(func.Return or "").. "</td>\n"); cf:write(" <td>" .. LinkifyString(func.Return or "", (a_InheritedName or a_ClassAPI.Name)).. "</td>\n");
cf:write(" <td>" .. LinkifyString(func.Notes or "") .. "</td>\n </tr>\n"); cf:write(" <td>" .. LinkifyString(func.Notes or "", (a_InheritedName or a_ClassAPI.Name)) .. "</td>\n </tr>\n");
end end
cf:write(" </table>\n\n"); cf:write(" </table>\n\n");
end end
@ -716,6 +732,8 @@ function WriteHtmlClass(a_ClassAPI, a_AllAPI)
end end
cf:write("</ul>\n"); cf:write("</ul>\n");
end end
local ClassName = a_ClassAPI.Name;
-- Build an array of inherited classes chain: -- Build an array of inherited classes chain:
local InheritanceChain = {}; local InheritanceChain = {};
@ -760,10 +778,10 @@ function WriteHtmlClass(a_ClassAPI, a_AllAPI)
cf:write(" </ul>\n\n"); cf:write(" </ul>\n\n");
-- Write the class description: -- Write the class description:
cf:write(" <a name=\"desc\"><hr /><h1>Class " .. a_ClassAPI.Name .. "</h1></a>\n"); cf:write(" <a name=\"desc\"><hr /><h1>Class " .. ClassName .. "</h1></a>\n");
if (a_ClassAPI.Desc ~= nil) then if (a_ClassAPI.Desc ~= nil) then
cf:write(" <p>"); cf:write(" <p>");
cf:write(LinkifyString(a_ClassAPI.Desc)); cf:write(LinkifyString(a_ClassAPI.Desc, ClassName));
cf:write(" </p>\n\n"); cf:write(" </p>\n\n");
end; end;
@ -790,7 +808,7 @@ function WriteHtmlClass(a_ClassAPI, a_AllAPI)
for i, cons in ipairs(a_ClassAPI.Constants) do for i, cons in ipairs(a_ClassAPI.Constants) do
cf:write(" <tr>\n <td>" .. cons.Name .. "</td>\n"); cf:write(" <tr>\n <td>" .. cons.Name .. "</td>\n");
cf:write(" <td>" .. cons.Value .. "</td>\n"); cf:write(" <td>" .. cons.Value .. "</td>\n");
cf:write(" <td>" .. LinkifyString(cons.Notes or "") .. "</td>\n </tr>\n"); cf:write(" <td>" .. LinkifyString(cons.Notes or "", ClassName) .. "</td>\n </tr>\n");
end end
cf:write(" </table>\n\n"); cf:write(" </table>\n\n");
@ -805,7 +823,7 @@ function WriteHtmlClass(a_ClassAPI, a_AllAPI)
if (a_ClassAPI.AdditionalInfo ~= nil) then if (a_ClassAPI.AdditionalInfo ~= nil) then
for i, additional in ipairs(a_ClassAPI.AdditionalInfo) do for i, additional in ipairs(a_ClassAPI.AdditionalInfo) do
cf:write(" <a name=\"additionalinfo_" .. i .. "\"><h1>" .. additional.Header .. "</h1></a>\n"); cf:write(" <a name=\"additionalinfo_" .. i .. "\"><h1>" .. additional.Header .. "</h1></a>\n");
cf:write(LinkifyString(additional.Contents)); cf:write(LinkifyString(additional.Contents, ClassName));
end end
end end
@ -824,10 +842,12 @@ function WriteHtmlHook(a_Hook)
LOG("Cannot write \"" .. fnam .. "\": \"" .. error .. "\"."); LOG("Cannot write \"" .. fnam .. "\": \"" .. error .. "\".");
return; return;
end end
local HookName = a_Hook.DefaultFnName;
f:write([[<!DOCTYPE html> f:write([[<!DOCTYPE html>
<html> <html>
<head> <head>
<title>MCServer API - ]] .. a_Hook.DefaultFnName .. [[ Hook</title> <title>MCServer API - ]] .. HookName .. [[ Hook</title>
<link rel="stylesheet" type="text/css" href="main.css" /> <link rel="stylesheet" type="text/css" href="main.css" />
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script> <script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>
<script src="http://google-code-prettify.googlecode.com/svn/trunk/src/lang-lua.js"></script> <script src="http://google-code-prettify.googlecode.com/svn/trunk/src/lang-lua.js"></script>
@ -840,10 +860,10 @@ function WriteHtmlHook(a_Hook)
</header> </header>
<p> <p>
]]); ]]);
f:write(LinkifyString(a_Hook.Desc)); 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 ");
f:write(a_Hook.DefaultFnName .. ". It has the following signature:\n\n"); f:write(a_Hook.DefaultFnName .. ". It has the following signature:\n\n");
f:write(" <pre class=\"prettyprint lang-lua\">function " .. a_Hook.DefaultFnName .. "("); f:write(" <pre class=\"prettyprint lang-lua\">function " .. HookName .. "(");
if (a_Hook.Params == nil) then if (a_Hook.Params == nil) then
a_Hook.Params = {}; a_Hook.Params = {};
end end
@ -855,7 +875,7 @@ function WriteHtmlHook(a_Hook)
end end
f:write(")</pre>\n\n <hr /><h1>Parameters:</h1>\n\n <table>\n <tr>\n <th>Name</th>\n <th>Type</th>\n <th>Notes</th>\n </tr>\n"); f:write(")</pre>\n\n <hr /><h1>Parameters:</h1>\n\n <table>\n <tr>\n <th>Name</th>\n <th>Type</th>\n <th>Notes</th>\n </tr>\n");
for i, param in ipairs(a_Hook.Params) do for i, param in ipairs(a_Hook.Params) do
f:write(" <tr>\n <td>" .. param.Name .. "</td>\n <td>" .. LinkifyString(param.Type) .. "</td>\n <td>" .. LinkifyString(param.Notes) .. "</td>\n </tr>\n"); f:write(" <tr>\n <td>" .. param.Name .. "</td>\n <td>" .. LinkifyString(param.Type, HookName) .. "</td>\n <td>" .. LinkifyString(param.Notes, HookName) .. "</td>\n </tr>\n");
end end
f:write(" </table>\n\n <p>" .. (a_Hook.Returns or "") .. "</p>\n\n"); f:write(" </table>\n\n <p>" .. (a_Hook.Returns or "") .. "</p>\n\n");
f:write([[ <hr /><h1>Code examples</h1> f:write([[ <hr /><h1>Code examples</h1>
@ -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