1
0

APIDump: Removed needless whitespace output.

This commit is contained in:
madmaxoft 2013-11-24 10:03:02 +01:00
parent 38fe16d8b6
commit 51b02854f9

View File

@ -289,50 +289,53 @@ function DumpAPIHtml()
end end
f:write([[<!DOCTYPE html> f:write([[<!DOCTYPE html>
<html> <html>
<head> <head>
<title>MCServer API - Index</title> <title>MCServer API - Index</title>
<link rel="stylesheet" type="text/css" href="main.css" /> <link rel="stylesheet" type="text/css" href="main.css" />
</head> </head>
<body> <body>
<div id="content"> <div id="content">
<header> <header>
<h1>MCServer API - Index</h1> <h1>MCServer API - Index</h1>
<hr /> <hr />
</header> </header>
<p>The API reference is divided into the following sections:</p> <p>The API reference is divided into the following sections:</p>
<ul>
<ul> <li><a href="#classes">Class index</a></li>
<li><a href="#classes">Class index</a></li> <li><a href="#hooks">Hooks</a></li>
<li><a href="#hooks">Hooks</a></li> <li><a href="#extra">Extra pages</a></li>
<li><a href="#extra">Extra pages</a></li> <li><a href="#docstats">Documentation statistics</a></li>
<li><a href="#docstats">Documentation statistics</a></li> </ul>
</ul> <hr />
<a name="classes"><h2>Class index</h2></a>
<hr /> <p>The following classes are available in the MCServer Lua scripting language:
<a name="classes"><h2>Class index</h2></a> <ul>
<p>The following classes are available in the MCServer Lua scripting language:</p> ]]);
<ul>
]]);
for i, cls in ipairs(API) do for i, cls in ipairs(API) do
f:write(" <li><a href=\"" .. cls.Name .. ".html\">" .. cls.Name .. "</a></li>\n"); f:write("<li><a href=\"", cls.Name, ".html\">", cls.Name, "</a></li>\n");
WriteHtmlClass(cls, API); WriteHtmlClass(cls, API);
end end
f:write([[ </ul> f:write([[
</ul></p>
<hr /> <hr />
<a name="hooks"><h2>Hooks</h2></a> <a name="hooks"><h2>Hooks</h2></a>
<p>
<p>A plugin can register to be called whenever an "interesting event" occurs. It does so by calling <a href="cPluginManager.html">cPluginManager</a>'s AddHook() function and implementing a callback function to handle the event.</p> A plugin can register to be called whenever an "interesting event" occurs. It does so by calling
<p>A plugin can decide whether it will let the event pass through to the rest of the plugins, or hide it from them. This is determined by the return value from the hook callback function. If the function returns false or no value, the event is propagated further. If the function returns true, the processing is stopped, no other plugin receives the notification (and possibly MCServer disables the default behavior for the event). See each hook's details to see the exact behavior.</p> <a href="cPluginManager.html">cPluginManager</a>'s AddHook() function and implementing a callback
function to handle the event.</p>
<table> <p>
<tr> A plugin can decide whether it will let the event pass through to the rest of the plugins, or hide it
<th>Hook name</th> from them. This is determined by the return value from the hook callback function. If the function
<th>Called when</th> returns false or no value, the event is propagated further. If the function returns true, the processing
</tr> is stopped, no other plugin receives the notification (and possibly MCServer disables the default
]]); behavior for the event). See each hook's details to see the exact behavior.</p>
<table>
<tr>
<th>Hook name</th>
<th>Called when</th>
</tr>
]]);
for i, hook in ipairs(Hooks) do for i, hook in ipairs(Hooks) do
if (hook.DefaultFnName == nil) then if (hook.DefaultFnName == nil) then
-- The hook is not documented yet -- The hook is not documented yet
@ -826,16 +829,16 @@ function WriteHtmlClass(a_ClassAPI, a_AllAPI)
end end
if (a_InheritedName ~= nil) then if (a_InheritedName ~= nil) then
cf:write(" <h2>Functions inherited from ", a_InheritedName, "</h2>\n"); cf:write("<h2>Functions inherited from ", a_InheritedName, "</h2>\n");
end end
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><th>Name</th><th>Parameters</th><th>Return value</th><th>Notes</th></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><td>", func.Name, "</td>\n");
cf:write(" <td>", LinkifyString(func.Params or "", (a_InheritedName or a_ClassAPI.Name)), "</td>\n"); cf:write("<td>", LinkifyString(func.Params or "", (a_InheritedName or a_ClassAPI.Name)), "</td>\n");
cf:write(" <td>", LinkifyString(func.Return or "", (a_InheritedName or a_ClassAPI.Name)), "</td>\n"); cf:write("<td>", LinkifyString(func.Return or "", (a_InheritedName or a_ClassAPI.Name)), "</td>\n");
cf:write(" <td>", LinkifyString(func.Notes or "<i>(undocumented)</i>", (a_InheritedName or a_ClassAPI.Name)), "</td>\n </tr>\n"); cf:write("<td>", LinkifyString(func.Notes or "<i>(undocumented)</i>", (a_InheritedName or a_ClassAPI.Name)), "</td></tr>\n");
end end
cf:write(" </table>\n\n"); cf:write("</table>\n");
end end
local function WriteConstantTable(a_Constants, a_Source) local function WriteConstantTable(a_Constants, a_Source)
@ -879,16 +882,16 @@ function WriteHtmlClass(a_ClassAPI, a_AllAPI)
end end
if (a_InheritedName ~= nil) then if (a_InheritedName ~= nil) then
cf:write(" <h2>Member variables inherited from ", a_InheritedName, "</h2>\n"); cf:write("<h2>Member variables inherited from ", a_InheritedName, "</h2>\n");
end end
cf:write(" <table>\n <tr>\n <th>Name</th>\n <th>Type</th>\n <th>Notes</th>\n </tr>\n"); cf:write("<table><tr><th>Name</th><th>Type</th><th>Notes</th></tr>\n");
for i, var in ipairs(a_Variables) do for i, var in ipairs(a_Variables) do
cf:write(" <tr>\n <td>", var.Name, "</td>\n"); cf:write("<tr><td>", 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.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.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
local function WriteDescendants(a_Descendants) local function WriteDescendants(a_Descendants)
@ -914,25 +917,23 @@ function WriteHtmlClass(a_ClassAPI, a_AllAPI)
CurrInheritance = CurrInheritance.Inherits; CurrInheritance = CurrInheritance.Inherits;
end end
cf:write([[<!DOCTYPE html> cf:write([[<!DOCTYPE html><html>
<html> <head>
<head>
<title>MCServer API - ]], a_ClassAPI.Name, [[ Class</title> <title>MCServer API - ]], a_ClassAPI.Name, [[ Class</title>
<link rel="stylesheet" type="text/css" href="main.css" /> <link rel="stylesheet" type="text/css" href="main.css" />
<link rel="stylesheet" type="text/css" href="prettify.css" /> <link rel="stylesheet" type="text/css" href="prettify.css" />
<script src="prettify.js"></script> <script src="prettify.js"></script>
<script src="lang-lua.js"></script> <script src="lang-lua.js"></script>
</head> </head>
<body> <body>
<div id="content"> <div id="content">
<header> <header>
<h1>]], a_ClassAPI.Name, [[</h1> <h1>]], a_ClassAPI.Name, [[</h1>
<hr /> <hr />
</header> </header>
<h1>Contents</h1> <h1>Contents</h1>
<p><ul>
<ul> ]]);
]]);
local HasInheritance = ((#a_ClassAPI.Descendants > 0) or (a_ClassAPI.Inherits ~= nil)); local HasInheritance = ((#a_ClassAPI.Descendants > 0) or (a_ClassAPI.Inherits ~= nil));
@ -947,52 +948,52 @@ function WriteHtmlClass(a_ClassAPI, a_AllAPI)
-- Write the table of contents: -- Write the table of contents:
if (HasInheritance) then if (HasInheritance) then
cf:write(" <li><a href=\"#inherits\">Inheritance</a></li>\n"); cf:write("<li><a href=\"#inherits\">Inheritance</a></li>\n");
end end
if (HasConstants) then if (HasConstants) then
cf:write(" <li><a href=\"#constants\">Constants</a></li>\n"); cf:write("<li><a href=\"#constants\">Constants</a></li>\n");
end end
if (HasVariables) then if (HasVariables) then
cf:write(" <li><a href=\"#variables\">Member variables</a></li>\n"); cf:write("<li><a href=\"#variables\">Member variables</a></li>\n");
end end
if (HasFunctions) then if (HasFunctions) then
cf:write(" <li><a href=\"#functions\">Functions</a></li>\n"); cf:write("<li><a href=\"#functions\">Functions</a></li>\n");
end end
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(" <li><a href=\"#additionalinfo_", i, "\">", (additional.Header or "<i>(No header)</i>"), "</a></li>\n"); cf:write("<li><a href=\"#additionalinfo_", i, "\">", (additional.Header or "<i>(No header)</i>"), "</a></li>\n");
end end
end end
cf:write(" </ul>\n\n"); cf:write("</ul></p>\n");
-- Write the class description: -- Write the class description:
cf:write(" <a name=\"desc\"><hr /><h1>" .. ClassName .. " class</h1></a>\n"); cf:write("<hr /><a name=\"desc\"><h1>", ClassName, " class</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, ClassName)); cf:write(LinkifyString(a_ClassAPI.Desc, ClassName));
cf:write(" </p>\n\n"); cf:write("</p>\n\n");
end; end;
-- Write the inheritance, if available: -- Write the inheritance, if available:
if (HasInheritance) then if (HasInheritance) then
cf:write(" <a name=\"inherits\">\n <hr /><h1>Inheritance</h1></a>\n"); cf:write("<hr /><a name=\"inherits\"><h1>Inheritance</h1></a>\n");
if (#InheritanceChain > 0) then if (#InheritanceChain > 0) then
cf:write(" <p>This class inherits from the following parent classes:</p>\n\n <ul>\n"); cf:write("<p>This class inherits from the following parent classes:<ul>\n");
for i, cls in ipairs(InheritanceChain) do for i, cls in ipairs(InheritanceChain) do
cf:write(" <li><a href=\"" .. cls.Name .. ".html\">" .. cls.Name .. "</a></li>\n"); cf:write("<li><a href=\"", cls.Name, ".html\">", cls.Name, "</a></li>\n");
end end
cf:write(" </ul>\n\n"); cf:write("</ul></p>\n");
end end
if (#a_ClassAPI.Descendants > 0) then if (#a_ClassAPI.Descendants > 0) then
cf:write(" <p>This class has the following descendants:\n"); cf:write("<p>This class has the following descendants:\n");
WriteDescendants(a_ClassAPI.Descendants); WriteDescendants(a_ClassAPI.Descendants);
cf:write(" </p>\n\n"); cf:write("</p>\n\n");
end end
end end
-- Write the constants: -- Write the constants:
if (HasConstants) then if (HasConstants) then
cf:write(" <a name=\"constants\"><hr /><h1>Constants</h1></a>\n"); cf:write("<a name=\"constants\"><hr /><h1>Constants</h1></a>\n");
WriteConstants(a_ClassAPI.Constants, a_ClassAPI.ConstantGroups, a_ClassAPI.NumConstantsInGroups, nil); WriteConstants(a_ClassAPI.Constants, a_ClassAPI.ConstantGroups, a_ClassAPI.NumConstantsInGroups, nil);
g_Stats.NumTotalConstants = g_Stats.NumTotalConstants + #a_ClassAPI.Constants + (a_ClassAPI.NumConstantsInGroups or 0); g_Stats.NumTotalConstants = g_Stats.NumTotalConstants + #a_ClassAPI.Constants + (a_ClassAPI.NumConstantsInGroups or 0);
for i, cls in ipairs(InheritanceChain) do for i, cls in ipairs(InheritanceChain) do
@ -1002,7 +1003,7 @@ function WriteHtmlClass(a_ClassAPI, a_AllAPI)
-- Write the member variables: -- Write the member variables:
if (HasVariables) then if (HasVariables) then
cf:write(" <a name=\"variables\"><hr /><h1>Member variables</h1></a>\n"); cf:write("<a name=\"variables\"><hr /><h1>Member variables</h1></a>\n");
WriteVariables(a_ClassAPI.Variables, nil); WriteVariables(a_ClassAPI.Variables, nil);
g_Stats.NumTotalVariables = g_Stats.NumTotalVariables + #a_ClassAPI.Variables; g_Stats.NumTotalVariables = g_Stats.NumTotalVariables + #a_ClassAPI.Variables;
for i, cls in ipairs(InheritanceChain) do for i, cls in ipairs(InheritanceChain) do
@ -1012,7 +1013,7 @@ function WriteHtmlClass(a_ClassAPI, a_AllAPI)
-- Write the functions, including the inherited ones: -- Write the functions, including the inherited ones:
if (HasFunctions) then if (HasFunctions) then
cf:write(" <a name=\"functions\"><hr /><h1>Functions</h1></a>\n"); cf:write("<a name=\"functions\"><hr /><h1>Functions</h1></a>\n");
WriteFunctions(a_ClassAPI.Functions, nil); WriteFunctions(a_ClassAPI.Functions, nil);
g_Stats.NumTotalFunctions = g_Stats.NumTotalFunctions + #a_ClassAPI.Functions; g_Stats.NumTotalFunctions = g_Stats.NumTotalFunctions + #a_ClassAPI.Functions;
for i, cls in ipairs(InheritanceChain) do for i, cls in ipairs(InheritanceChain) do
@ -1023,19 +1024,12 @@ function WriteHtmlClass(a_ClassAPI, a_AllAPI)
-- Write the additional infos: -- Write the additional infos:
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, ClassName)); cf:write(LinkifyString(additional.Contents, ClassName));
end end
end end
cf:write([[ cf:write([[</div><script>prettyPrint();</script></body></html>]]);
</div>
<script>
prettyPrint();
</script>
</body>
</html>
]]);
cf:close(); cf:close();
end end
@ -1052,27 +1046,26 @@ function WriteHtmlHook(a_Hook)
end end
local HookName = a_Hook.DefaultFnName; local HookName = a_Hook.DefaultFnName;
f:write([[<!DOCTYPE html> f:write([[<!DOCTYPE html><html>
<html> <head>
<head> <title>MCServer API - ]], HookName, [[ 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" />
<link rel="stylesheet" type="text/css" href="prettify.css" /> <link rel="stylesheet" type="text/css" href="prettify.css" />
<script src="prettify.js"></script> <script src="prettify.js"></script>
<script src="lang-lua.js"></script> <script src="lang-lua.js"></script>
</head> </head>
<body> <body>
<div id="content"> <div id="content">
<header> <header>
<h1>]] .. a_Hook.Name .. [[</h1> <h1>]], a_Hook.Name, [[</h1>
<hr /> <hr />
</header> </header>
<p> <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 ");
f:write(a_Hook.DefaultFnName .. ". It has the following signature:\n\n"); f:write(a_Hook.DefaultFnName, ". It has the following signature:\n");
f:write(" <pre class=\"prettyprint lang-lua\">function " .. HookName .. "("); 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
@ -1082,30 +1075,22 @@ function WriteHtmlHook(a_Hook)
end end
f:write(param.Name); f:write(param.Name);
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<hr /><h1>Parameters:</h1>\n<table><tr><th>Name</th><th>Type</th><th>Notes</th></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, HookName) .. "</td>\n <td>" .. LinkifyString(param.Notes, HookName) .. "</td>\n </tr>\n"); f:write("<tr><td>", param.Name, "</td><td>", LinkifyString(param.Type, HookName), "</td><td>", LinkifyString(param.Notes, HookName), "</td></tr>\n");
end end
f:write(" </table>\n\n <p>" .. (a_Hook.Returns or "") .. "</p>\n\n"); f:write("</table>\n<p>" .. (a_Hook.Returns or "") .. "</p>\n\n");
f:write([[ <hr /><h1>Code examples</h1> f:write([[<hr /><h1>Code examples</h1><h2>Registering the callback</h2>]]);
<h2>Registering the callback</h2> f:write("<pre class=\"prettyprint lang-lua\">\n");
]]);
f:write(" <pre class=\"prettyprint lang-lua\">\n");
f:write([[cPluginManager.AddHook(cPluginManager.]] .. a_Hook.Name .. ", My" .. a_Hook.DefaultFnName .. [[);]]); f:write([[cPluginManager.AddHook(cPluginManager.]] .. a_Hook.Name .. ", My" .. a_Hook.DefaultFnName .. [[);]]);
f:write("</pre>\n\n"); f:write("</pre>\n\n");
local Examples = a_Hook.CodeExamples or {}; local Examples = a_Hook.CodeExamples or {};
for i, example in ipairs(Examples) do for i, example in ipairs(Examples) do
f:write(" <h2>" .. (example.Title or "<i>missing Title</i>") .. "</h2>\n"); f:write("<h2>", (example.Title or "<i>missing Title</i>"), "</h2>\n");
f:write(" <p>" .. (example.Desc or "<i>missing Desc</i>") .. "</p>\n\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> f:write([[</div><script>prettyPrint();</script></body></html>]]);
<script>
prettyPrint();
</script>
</body>
</html>]]);
f:close(); f:close();
end end