From 22102b4a644fa9ca2abdac791a31ad70dd7641ec Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 18 Oct 2013 12:30:06 +0200 Subject: APIDump: Makes a list of bad links. This fixes #219. --- MCServer/Plugins/APIDump/main.lua | 95 ++++++++++++++++++++++++++++++++------- 1 file changed, 78 insertions(+), 17 deletions(-) (limited to 'MCServer/Plugins/APIDump') 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 " .. hook.Name .. "\n (No documentation yet)\n \n"); table.insert(UndocumentedHooks, hook.Name); else - f:write(" \n " .. hook.Name .. "\n " .. LinkifyString(hook.CalledWhen) .. "\n \n"); + f:write(" \n " .. hook.Name .. "\n " .. LinkifyString(hook.CalledWhen, hook.Name) .. "\n \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 \n \n \n \n \n"); for i, func in ipairs(a_Functions) do cf:write(" \n \n"); - cf:write(" \n"); - cf:write(" \n"); - cf:write(" \n \n"); + cf:write(" \n"); + cf:write(" \n"); + cf:write(" \n \n"); end cf:write("
NameParametersReturn valueNotes
" .. func.Name .. "" .. LinkifyString(func.Params or "").. "" .. LinkifyString(func.Return or "").. "" .. LinkifyString(func.Notes or "") .. "
" .. LinkifyString(func.Params or "", (a_InheritedName or a_ClassAPI.Name)).. "" .. LinkifyString(func.Return or "", (a_InheritedName or a_ClassAPI.Name)).. "" .. LinkifyString(func.Notes or "", (a_InheritedName or a_ClassAPI.Name)) .. "
\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("

Class " .. a_ClassAPI.Name .. "

\n"); + cf:write("

Class " .. ClassName .. "

\n"); if (a_ClassAPI.Desc ~= nil) then cf:write("

"); - cf:write(LinkifyString(a_ClassAPI.Desc)); + cf:write(LinkifyString(a_ClassAPI.Desc, ClassName)); 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("

" .. additional.Header .. "

\n"); - cf:write(LinkifyString(additional.Contents)); + cf:write(LinkifyString(additional.Contents, ClassName)); end end @@ -824,10 +842,12 @@ function WriteHtmlHook(a_Hook) LOG("Cannot write \"" .. fnam .. "\": \"" .. error .. "\"."); return; end + local HookName = a_Hook.DefaultFnName; + f:write([[ - MCServer API - ]] .. a_Hook.DefaultFnName .. [[ Hook + MCServer API - ]] .. HookName .. [[ Hook @@ -840,10 +860,10 @@ function WriteHtmlHook(a_Hook)

]]); - f:write(LinkifyString(a_Hook.Desc)); + f:write(LinkifyString(a_Hook.Desc, HookName)); f:write("

\n

Callback function

\n

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 \n \n \n \n"); for i, param in ipairs(a_Hook.Params) do - f:write(" \n \n \n \n \n"); + f:write(" \n \n \n \n \n"); end f:write("
NameTypeNotes
" .. param.Name .. "" .. LinkifyString(param.Type) .. "" .. LinkifyString(param.Notes) .. "
" .. param.Name .. "" .. LinkifyString(param.Type, HookName) .. "" .. LinkifyString(param.Notes, HookName) .. "
\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 + + + + -- cgit v1.2.3