From 1f1216d56ddb5e3dcb13192bf5ebbca62a088ed4 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 13 Sep 2013 10:22:04 +0200 Subject: APIDump: Added support for inheritance --- MCServer/Plugins/APIDump/main.lua | 97 +++++++++++++++++++++++++++------------ 1 file changed, 68 insertions(+), 29 deletions(-) (limited to 'MCServer/Plugins/APIDump/main.lua') diff --git a/MCServer/Plugins/APIDump/main.lua b/MCServer/Plugins/APIDump/main.lua index 3988857c9..3ec6a1ccd 100644 --- a/MCServer/Plugins/APIDump/main.lua +++ b/MCServer/Plugins/APIDump/main.lua @@ -205,7 +205,7 @@ function DumpAPIHtml() ]]); for i, cls in ipairs(API) do f:write("
  • " .. cls.Name .. "
  • \n"); - WriteHtmlClass(cls); + WriteHtmlClass(cls, API); end f:write(""); f:close(); @@ -223,6 +223,7 @@ function ReadDescriptions(a_API) local APIDesc = g_APIDesc.Classes[cls.Name]; if (APIDesc ~= nil) then cls.Desc = APIDesc.Desc; + cls.Inherits = APIDesc.Inherits; if (APIDesc.Functions ~= nil) then -- Assign function descriptions: @@ -267,7 +268,7 @@ end -function WriteHtmlClass(a_ClassAPI) +function WriteHtmlClass(a_ClassAPI, a_AllAPI) local cf, err = io.open("API/" .. a_ClassAPI.Name .. ".html", "w"); if (cf == nil) then return; @@ -275,10 +276,49 @@ function WriteHtmlClass(a_ClassAPI) local function LinkifyString(a_String) -- TODO: Make a link out of anything with the special linkifying syntax {{link|title}} - -- a_String:gsub("{{([^|]*)|[^}]*}}", "%2"); + -- a_String:gsub("{{([^|]*)|([^}])*}}", "%2"); return a_String; end + -- Returns the ClassAPI for the inherited class, or nil if not found + local function FindInheritedClassAPI(a_AllAPI, a_InheritedClassName) + if (a_InheritedClassName == nil) then + return nil; + end + for i, cls in ipairs(a_AllAPI) do + if (cls.Name == a_InheritedClassName) then + return cls; + end + end + return nil; + end + + -- Writes a table containing all functions in the specified list, with an optional "inherited from" header when a_InheritedName is valid + local function WriteFunctions(a_Functions, a_InheritedName) + if (#a_Functions == 0) then + return; + end + if (a_InheritedName ~= nil) then + cf:write("

    Functions inherited from " .. a_InheritedName .. "

    "); + end + cf:write("\n"); + for i, func in ipairs(a_Functions) do + cf:write(""); + cf:write(""); + cf:write(""); + cf:write("\n"); + end + cf:write("
    NameParametersReturn valueNotes
    " .. func.Name .. "" .. LinkifyString(func.Params or "").. "" .. LinkifyString(func.Return or "").. "" .. LinkifyString(func.Notes or "") .. "
    \n"); + end + + -- Build an array of inherited classes chain: + local InheritanceChain = {}; + local CurrInheritance = FindInheritedClassAPI(a_AllAPI, a_ClassAPI.Inherits); + while (CurrInheritance ~= nil) do + table.insert(InheritanceChain, CurrInheritance); + CurrInheritance = FindInheritedClassAPI(a_AllAPI, CurrInheritance.Inherits); + end + cf:write([[MCServer API - ]] .. a_ClassAPI.Name .. [[ @@ -287,45 +327,44 @@ function WriteHtmlClass(a_ClassAPI) ]]); -- Write the table of contents: - if (#a_ClassAPI.Constants > 0) then - cf:write("
  • Constants
  • \n"); - end - if (#a_ClassAPI.Functions > 0) then - cf:write("
  • Functions
  • \n"); + if (a_ClassAPI.Inherits ~= nil) then + cf:write("
  • Inheritance
  • \n"); end + cf:write("
  • Constants
  • \n"); + cf:write("
  • Functions
  • \n"); cf:write(""); -- Write the class description: - cf:write("

    " .. a_ClassAPI.Name .. "

    \n"); + cf:write("

    " .. a_ClassAPI.Name .. " class

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

    "); cf:write(a_ClassAPI.Desc); cf:write("

    \n"); end; - -- Write the constants: - if (#a_ClassAPI.Constants > 0) then - cf:write("

    Constants

    \n"); - cf:write("\n"); - for i, cons in ipairs(a_ClassAPI.Constants) do - cf:write(""); - cf:write(""); - cf:write("\n"); + -- Write the inheritance, if available: + if (a_ClassAPI.Inherits ~= nil) then + cf:write("

    Inheritance

    \n"); + for i, cls in ipairs(InheritanceChain) do + cf:write("
  • " .. cls.Name .. "
  • "); end - cf:write("
    NameValueNotes
    " .. cons.Name .. "" .. cons.Value .. "" .. LinkifyString(cons.Notes or "") .. "
    \n"); end - -- Write the functions: - if (#a_ClassAPI.Functions > 0) then - cf:write("

    Functions

    \n"); - cf:write("\n"); - for i, func in ipairs(a_ClassAPI.Functions) do - cf:write(""); - cf:write(""); - cf:write(""); - cf:write("\n"); - end - cf:write("
    NameParametersReturn valueNotes
    " .. func.Name .. "" .. LinkifyString(func.Params or "").. "" .. LinkifyString(func.Return or "").. "" .. LinkifyString(func.Notes or "") .. "
    \n"); + -- Write the constants: + cf:write("

    Constants

    \n"); + cf:write("\n"); + for i, cons in ipairs(a_ClassAPI.Constants) do + cf:write(""); + cf:write(""); + cf:write("\n"); + end + cf:write("
    NameValueNotes
    " .. cons.Name .. "" .. cons.Value .. "" .. LinkifyString(cons.Notes or "") .. "
    \n"); + + -- Write the functions, including the inherited ones: + cf:write("

    Functions

    \n"); + WriteFunctions(a_ClassAPI.Functions, nil); + for i, cls in ipairs(InheritanceChain) do + WriteFunctions(cls.Functions, cls.Name); end cf:write(""); -- cgit v1.2.3