Module:Codedoc

-- --| Reads a file and outputs its comments. --b Pedro M. Rabinovitch  --$Id: dofile.lua,v 1.2 2003/10/20 03:35:08 miller Exp $ -- Wikifying by Dessamator local p = {} local ProcLua = require ('Dev:Codedoc/Procsrc') local args = require ("Dev:Arguments").getArgs

function createDocs(page) local opt = { complete = true, proc_private = true, hideHeader = true -- hides the header }   local docOutput = "" local text = mw.title.new( page ):getContent local cmt = ProcLua:process( text, opt ) local br = " " local scriptInfo = mw.html.create( 'div' ) scriptInfo :tag("h2") :wikitext("Script information") :done local metaInfo = "" if not opt.hideHeader then metaInfo = cmt.header.authors[1] and "\n;Authors: \n:".. cmt.header.authors[1] or "".. cmt.header.purpose and "\n;Purpose: \n:".. cmt.header.purpose or "".. cmt.header.revision and "\n;Revision: \n:".. cmt.header.revision or "" .. cmt.header.todo[1] and "\n;Todo: \n:".. cmt.header.todo[1] or "" end local functionInfo = "\n" ..tostring(createFunctionTables(cmt.functions))

return tostring(scriptInfo) .. metaInfo .. functionInfo end

function createFunctionTables(functionTable) local sFunctions local docOutput = mw.html.create( 'div' ) local returnData docOutput:tag("h2") :wikitext("Functions"):done for _, objDetails in pairs(functionTable) do       docOutput:tag("h3") :wikitext(objDetails.name) :done :tag("h4") :wikitext("Parameters"):done sFunctions = mw.html.create( 'table' ) :addClass( 'wikitable' ) :addClass( 'sortable' ) :css( 'width', '100%' ) :tag( 'tr' ) :tag( 'th' ) :wikitext( 'Name' ) :done :tag( 'th' ) :wikitext( 'type?' ) :done :tag( 'th' ) :wikitext( 'purpose' ) :done :done for paramName, paramDetails in pairs(objDetails.parameters) do           sFunctions :tag( 'tr' ) :tag( 'td' ) :wikitext( paramDetails.name ) :done :tag( 'td' ) :wikitext (paramDetails.type ) :done :tag( 'td' ) :wikitext( paramDetails.purpose ) :done :done end returnData = mw.html.create( 'table' ) :addClass( 'wikitable' ) :addClass( 'sortable' ) :css( 'width', '100%' ) returnData :tag( 'tr' ) :tag( 'th' ) :wikitext( 'Return type' ) :done :tag( 'th' ) :wikitext( 'Return purpose' ) :done for _, returnDetails in pairs(objDetails.returns) do           returnData :tag( 'tr' ) :tag( 'td' ) :wikitext( returnDetails.type ) :done :tag( 'td' ) :wikitext (returnDetails.purpose ) :done end docOutput :node(sFunctions):done :node(returnData) end return docOutput end

function p.main(frame) local page = args(frame)[1] local prefix = mw.text.split(":")[1] or "" if prefix:lower ~= "module" then return createDocs("module:" .. page) end return createDocs(page) end

return p