Rocket League Esports Wiki
Advertisement

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

local util_args = require('Module:ArgsUtil')
local util_html = require('Module:HtmlUtil')
local util_map = require('Module:MapUtil')
local util_table = require('Module:TableUtil')
local i18n = require('Module:i18nUtil')

local DOC_COLUMNS = { 'index', 'field', 'type', 'desc' }

local h = {}

local p = {}
function p.main(frame)
	local args = util_args.overwrite()
	if util_args.castAsBool(args.doc) then
		return p.doc(args)
	end
	if util_args.castAsBool(args.forgadget) then
		return p.forGadget(args)
	end
	return p.declare(args)
end

function p.declare(args)
	local tableName = args[1]
	local cargoArgs = h.concatFieldsToArgs(h.getArgs(tableName))
	return mw.getCurrentFrame():callParserFunction{
		name = ('#cargo_declare:_table=%s'):format(tableName),
		args = cargoArgs
	}
end

function p.doc(args)
	i18n.init('CargoDeclare')
	local tableName = args[1]
	return h.makeDocTable(h.getArgs(tableName))
end

function p.forGadget(args)
	local cargoArgs = h.getArgs(args[1])
	return util_table.concat(cargoArgs, ';;;', h.concatForJson)
end

function h.getArgs(tableName)
	return require('Module:CargoDeclare/' .. tableName)
end

function h.concatFieldsToArgs(fields)
	util_map.inPlace(fields, h.concatFieldToArg)
	return fields
end

function h.concatFieldToArg(field)
	return ('%s=%s'):format(field.field, field.type)
end

function h.makeDocTable(fields)
	local output = mw.html.create('table')
		:addClass('wikitable')
	util_map.rowsInPlace(fields, h.formatForDocTable)
	util_html.printHeaderFromI18n(output, DOC_COLUMNS)
	util_html.printRowsByList(output, fields, DOC_COLUMNS)
	return output
end

function h.formatForDocTable(row)
	
end

function h.concatForJson(field)
	return ('%s:::%s'):format(field.field, field.desc)
end

return p
Advertisement