Module:BracketCopyableCode

local util_args = require('Module:ArgsUtil') local util_text = require('Module:TextUtil') local FIELDS = { 'team', 'score' } local MATCH_FIELDS = { 'winner' } local sep = '%s*,%s*'

local h = {}

function h.getFields(fields, matchfields) if fields then FIELDS = util_text.split(fields,sep) end if matchfields then MATCH_FIELDS = util_text.split(matchfields,sep) end end

function h.makeOutput(settings, bracketname) local tbl = { (' *****[%s'):format(bracketname), h.makeAllFields(settings), ']***** ',	}	return table.concat(tbl,'\n') end

function h.makeAllFields(settings) local tbl = {} for round, col in ipairs(settings) do		tbl[round] = h.makeColumn(col.matches, round) end return table.concat(tbl,'\n\n') end

function h.makeColumn(col, round) local tbl = {} for i, data in ipairs(col) do		if data.display == 'match' then tbl[#tbl+1] = h.makeMatch(round, i)		end end return table.concat(tbl,'\n') end

function h.makeMatch(round, match) local tbl = {} for i = 1, 2 do		local row = {} for _, field in ipairs(FIELDS) do			row[#row+1] = h.concatField(field, round, match, i)		end tbl[i] = table.concat(row,' ') end tbl[#tbl+1] = h.makeFinalMatchFields(round, match) return table.concat(tbl,'\n') end

function h.concatField(field, round, match, i)	return ('|R%sM%s_%s_%s= '):format(round, match, field, i) end

function h.makeFinalMatchFields(round, match) local tbl = {} for _, field in ipairs(MATCH_FIELDS) do		tbl[#tbl+1] = h.concatRound(field, round, match) end return table.concat(tbl, ' ') end

function h.concatRound(field, round, match) return ('|R%sM%s_%s= '):format(round, match, field) end

local p = {} function p.main(frame) local args = util_args.merge(true) local bracketname = args[1] local settings = require('Module:Bracket/'.. bracketname) h.getFields(args.fields, args.matchfields) return h.makeOutput(settings, bracketname) end return p