Module:Figurines: Difference between revisions
Jump to navigation
Jump to search
PhantomCaleb (talk | contribs) No edit summary |
PhantomCaleb (talk | contribs) No edit summary |
||
Line 5: | Line 5: | ||
local utilsTable = require("Module:UtilsTable") | local utilsTable = require("Module:UtilsTable") | ||
local CARGO_TABLE = " | local CARGO_TABLE = "FigurinesNew" | ||
local CATEGORY_INVALID_ARGS = require("Module:Constants/category/invalidArgs") | local CATEGORY_INVALID_ARGS = require("Module:Constants/category/invalidArgs") | ||
local STORING_PAGE_FORMAT = "User:PhantomCaleb/Sandbox" | local STORING_PAGE_FORMAT = "User:PhantomCaleb/Sandbox" | ||
Line 56: | Line 56: | ||
figurineName = figurineName and string.gsub(figurineName, "%[Player Name%]", "Link") | figurineName = figurineName and string.gsub(figurineName, "%[Player Name%]", "Link") | ||
figurineName = figurineName and string.gsub(figurineName, "%s%[[%d]%]", "") | figurineName = figurineName and string.gsub(figurineName, "%s%[[%d]%]", "") | ||
result = result..frame: | result = result..frame:expandTemplate({ | ||
name = " | name = "Figurines/Sandbox", | ||
args = { | args = { | ||
game = args.game, | game = args.game, | ||
number = numberCell.raw, | |||
name = figurineName, | |||
figurine = figurineCell.content, | |||
description = descriptionCell.raw, | |||
subjects = subjectsCell.raw, | |||
} | } | ||
}) | }) |
Revision as of 18:19, 21 November 2022
This is the main module for the following templates:
local p = {}
local h = {}
local DataTable = require("Module:Data Table")
local utilsTable = require("Module:UtilsTable")
local CARGO_TABLE = "FigurinesNew"
local CATEGORY_INVALID_ARGS = require("Module:Constants/category/invalidArgs")
local STORING_PAGE_FORMAT = "User:PhantomCaleb/Sandbox"
-- local STORING_PAGE_FORMAT = "Figurines in %"
local COLUMN_DESCRIPTION = "Description"
local COLUMN_FIGURINE = "Figurine"
local COLUMN_NUMBER = "Number"
local COLUMN_SUBJECTS = "Subject(s)"
function h.warn(msg, ...)
local utilsError = require("Module:UtilsError")
msg = string.format(msg, ...)
utilsError.warn(msg)
end
function h.warnEmpty(column, rowIndex)
h.warn("The value for column <code>%s</code> in row %d should not be empty.", column, rowIndex)
return "[[Category:"..CATEGORY_INVALID_ARGS.."]]"
end
function p.Store(frame)
local categories = ""
local result = ""
local dataTable, dataTableCategories = DataTable.Main(frame, {}, function(args, dataRows, columnHeaders)
local requiredColumns = {COLUMN_DESCRIPTION, COLUMN_FIGURINE, COLUMN_SUBJECTS}
local missingColumns = utilsTable.difference(requiredColumns, columnHeaders)
if #missingColumns > 0 then
local utilsMarkup = require("Module:UtilsMarkup")
missingColumns = utilsTable.map(missingColumns, utilsMarkup.code)
h.warn("Columns %s are required.", mw.text.listToText(missingColumns))
categories = categories.."[[Category:"..CATEGORY_INVALID_ARGS.."]]"
end
for i, row in ipairs(dataRows) do
local cellsByColumn = utilsTable.keyBy(row.cells, "columnHeader")
local figurineCell = cellsByColumn[COLUMN_FIGURINE] or {}
local subjectsCell = cellsByColumn[COLUMN_SUBJECTS] or {}
local descriptionCell = cellsByColumn[COLUMN_DESCRIPTION] or {}
local numberCell = cellsByColumn[COLUMN_NUMBER] or {}
if figurineCell.raw == nil or figurineCell.raw == "" then
categories = categories..h.warnEmpty(COLUMN_FIGURINE, i)
end
if subjectsCell.raw == nil or subjectsCell.raw == "" then
categories = categories..h.warnEmpty(COLUMN_SUBJECTS, i)
end
if descriptionCell.raw == nil or descriptionCell.raw == "" then
categories = categories..h.warnEmpty(COLUMN_DESCRIPTION, i)
end
if mw.title.getCurrentTitle().nsText ~= "Template" then
local figurineName = figurineCell.raw
figurineName = figurineName and string.gsub(figurineName, "%[Player Name%]", "Link")
figurineName = figurineName and string.gsub(figurineName, "%s%[[%d]%]", "")
result = result..frame:expandTemplate({
name = "Figurines/Sandbox",
args = {
game = args.game,
number = numberCell.raw,
name = figurineName,
figurine = figurineCell.content,
description = descriptionCell.raw,
subjects = subjectsCell.raw,
}
})
end
end
end)
return result..dataTable, categories..dataTableCategories
end
p.Templates = {
["Figurines/Store"] = {
purpose = string.format("An extension of [[Template:Data Table]] for [[Figurine]] listings. Data is stored in the [[Special:CargoTables/%s|%s]] Cargo table for retrieval by [[Template:Figurines]].", CARGO_TABLE, CARGO_TABLE),
usage = "See [[Template:Data Table]] for more information",
paramOrder = {"name", "game", "columns", "..."},
params = {
name = {
type = "string",
required = true,
desc = "See the <code>name</code> parameter of [[Template:Data Table]].",
},
game = {
type = "string",
required = true,
desc = "See the <code>game</code> parameter of [[Template:Data Table]].",
},
columns = {
type = "string",
desc = string.format("See the <code>columns</code> parameter of [[Template:Data Table]].<p>For [[Template:Figurines]] to function correctly, there must be columns named <code>%s</code>, <code>%s</code>, and <code>%s</code>.</p>", COLUMN_FIGURINE, COLUMN_SUBJECTS, COLUMN_DESCRIPTION),
},
["..."] = {
name = "cells",
placeholder = "cell",
desc = "See the <code>cells</code> parameter of [[Template:Data Table]].",
},
}
},
}
return p