Module:TemplateData

From Vintage Story Wiki
Revision as of 11:57, 28 August 2022 by Sana (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:TemplateData/doc

local p = {}

function p.main(f)
	local args = require( 'Module:ProcessArgs' ).merge( true )
	
	local rows = {}
	for i=1, #args.params, 1 do
	    local label = args.params[i].label or args.params[i].name
	    local aliases = '<code>' .. args.params[i].name .. '</code>'
	    local description = args.params[i].description or '<i>No description</i>'
	    local type = args.params[i].type or '<i>Unknown</i>'
	    local status = 'optional'
	    
	    if args.params.aliases then
	        for  i=1, #args.params.aliases, 1 do
	            aliases = aliases .. '<code>' .. args.params.aliases[i] .. '</code>'
	        end
	    end
	    if args.params[i].required then status = '<b>required</b>'
	    elseif args.params[i].suggested then status = 'suggested' end
	
	    local row = '<tr><th style="font-weight: normal;">' .. label .. '</th><td>' .. aliases .. '</td><td>' .. description .. '</td><td>' .. type .. '</td><td>' .. status .. '</td></tr>'
	    
	    table.insert(rows, row)
	end

	local body = {
			'<table class="wikitable" style="margin:2em">',
				'<caption>Template parameters</caption>',
				'<tr>',
					'<th colspan="2">Parameter</th><th>Description</th><th>Type</th><th>Status</th>',
				'</tr>'
	}
	body = table.concat(body, '\n') .. table.concat(rows, '\n') .. '</table>'
	return body
end
return p