Module:Variable

local p = {} local Data = mw.loadData("Module:Variable/Data")

local Color = require("Module:Color") local utilsArg = require("Module:UtilsArg") local utilsMarkup = require("Module:UtilsMarkup") local utilsTable = require("Module:UtilsTable")

local enum = utilsTable.keys(Data.variables) enum.reference = "Template:Variable"

function p.Main(frame) local args, err = utilsArg.parse(frame:getParent.args, p.Templates.Variable) local categories = err and err.categoryText or "" if err and err.args.var then return "", categories end

local varConfig = Data.variables[args.var] or {} local tooltip = varConfig.tooltip or "" local default = varConfig.default local placeholder = varConfig.placeholder or "" local color = varConfig.color

local display = varConfig.default or "["..placeholder.."]" local content = utilsMarkup.tooltip(display, tooltip) if color then content = Color.color(color, content) end

return content, categories end

function p.ListVariables(frame) local DataTable = require("Module:Data Table") local Franchise = require("Module:Franchise") local utilsString = require("Module:UtilsString")

local columns = {"Game [Rowspan]", "Variable [Description]", "Output"} local rows = {} for varName, varConfig in pairs(Data.variables) do		local varParts = utilsString.split(varName, " ") local gameCode = varParts[1] local gameVarName = table.concat(utilsTable.tail(varParts), " ") local game = Franchise.link(gameCode) local input = "" local output = frame:preprocess(input) input = " "

local row = {game, input, output} row.game = Franchise.canonOrder(gameCode) row.name = gameVarName table.insert(rows, row) end rows = utilsTable.sortBy(rows, {"game", "name"}) local dataTable = DataTable.printTable(rows, {		columns = columns	}) return dataTable end

p.Templates = { ["Variable"] = { description = "Used to indicate a variable in game transcripts", params = { [1] = {				name = "var", type = "string", desc = "A variable name.", enum = enum, },		},	}, }

return p