Module:MakeDocumentation

local p = {}

function getParams(frame) --combine args

local result = "" local directArgs = frame.args local parentArgs = frame:getParent.args local args = {}

for _, argType in ipairs{ directArgs, parentArgs } do       for key, val in pairs( argType ) do            args[key] = val end end return args end

function filterParams(frame) local args = getParams(frame) local result = {}

for k, v in pairs(args) do       if string.match(k, 'param%d+name') or string.match(k, 'param%d+type') or string.match(k, 'param%d+desc') then result[k] = v       end end

return result end --literally same as the above but with an extra check. should be refactored later. actually like 90% of this could be refactored, but there's no point right now. function filterMethodParams(frame) local args = getParams(frame) local result = {}

for k, v in pairs(args) do       if string.match(k, 'param%d+name') or string.match(k, 'param%d+type') or string.match(k, 'param%d+desc') or string.match(k, 'param%d+value') then result[k] = v       end end

return result end

function isEmpty(s) return s == nil or s == '' end

function getTableLength(t) local count = 0 for _ in pairs(t) do       count = count + 1 end return count end

function p.makeHeaderFromParams(frame) local args = filterParams(frame) result = {} for count = 1, (math.floor(getTableLength(args) / 3)) do       type = args["param" .. count .. "type"] name = args["param" .. count .. "name"] if (not isEmpty(type)) then result[count] = type elseif (name) then result[count] = name else break end end

return string.sub(table.concat(result, ", "), 0, -1) end

function p.makeSyntaxFromParams(frame) local args = filterParams(frame) result = {} for count = 1, (math.floor(getTableLength(args) / 3)) do       type = isEmpty(args["param" .. count .. "type"]) and "" or args["param" .. count .. "type"] name = args["param" .. count .. "name"] if (name) then if (not isEmpty(type)) then result[count] = type .. ' ' .. name else result[count] = name end else break end end

return string.sub(table.concat(result, ", "), 0, -1) end

function p.makeMethodSignatureFromParams(frame) local countargs = filterParams(frame) local args = filterMethodParams(frame) result = {} for count = 1, (math.floor(getTableLength(countargs) / 3)) do       type = args["param" .. count .. "type"] valueString = isEmpty(args["param" .. count .. "value"]) and "" or (' = ' .. args["param" .. count .. "value"]) name = args["param" .. count .. "name"] if (name) then if (not isEmpty(type)) then result[count] = type .. ' ' .. name .. valueString else result[count] = name .. valueString end else break end end

return string.sub(table.concat(result, ", "), 0, -1) end

function p.makeDocFromParams(frame) local args = filterParams(frame) result = {} for count = 1, (math.floor(getTableLength(args) / 3)) do       desc = isEmpty(args["param" .. count .. "desc"]) and "No description provided." or args["param" .. count .. "desc"] name = ' - ' if (name) then result[count] = name .. ' ' .. desc else break end end

return table.concat(result, "\n\n") end

function p.debug(frame) local args = filterParams(frame) return table.concat(args, "\n") end

return p