Module:Descriptions/Store

local p = {} local h = {}

local DataTable = require("Module:Data Table") local utilsMarkup = require("Module:UtilsMarkup") local utilsTable = require("Module:UtilsTable")

local function parseFile(subject, game, fileType) local Franchise = require("Module:Franchise") local GalleryList = require("Module:Gallery List") local fileType = fileType or Franchise.graphics(game) == "2D" and "Sprite" or "Icon" local entry = GalleryList.parseEntry(subject, game, fileType) return entry.file end

function p.DataTableStore(frame) return DataTable.Main(frame, {		params = p.Templates["Data Table/Descriptions"].params,		storeFn = h.storeDescriptions,		requiredColumns = {"Description"},	}) end

function h.storeDescriptions(args, rows) local columns, tags = DataTable.extractColumnTags(args.columns) local subjectColumn = args.subjectColumn or columns[1] local columnIndex = utilsTable.findIndex(columns, function(column)		return column == subjectColumn	end) local imageTag = columnIndex and utilsTable.find(tags[columnIndex], function(tag)		return tag.name == "Image"	end)

for i, row in ipairs(rows) do		local description = mw.text.killMarkers(row["Description"] or "") local subject = utilsMarkup.separateMarkup(row[subjectColumn] or "") local file if subject ~= "" and imageTag then file = parseFile(subject, args.game, imageTag.args[1]) end if description ~= "" and subject ~= "" then mw.getCurrentFrame:expandTemplate({				title = "Descriptions/Store",				args = {					game = args.game,					descriptionType = args.descriptionType,					subjectType = args.subjectType or subjectColumn,					subject = subject,					description = description,					image = file,				},			}) end end end

p.Templates = { ["Data Table/Descriptions"] = { format = "block", params = { descriptionType = { type = "string", trim = true, nilIfEmpty = true, desc = "", },			subjectType = { type = "string", trim = true, nilIfEmpty = true, desc = "", },			subjectColumn = { type = "string", trim = true, nilIfEmpty = true, desc = "", },		},	},	["Descriptions/Store"] = { format = "block", paramOrder = {"game", "descriptionType", "subjectType", "subject", "context", "description", "image"}, params = { game = { required = true, type = "string", desc = "A game code from Data:Franchise.", },			descriptionType = { required = true, type = "string", desc = "The type of description, e.g. ." },			subjectType = { required = true, type = "string", desc = "The type of the subject, e.g.,  ,  , etc.", },			subject = { required = true, type = "wiki-page-name", desc = "A wiki article name referring to the subject being described.", },			context = { type = "content", desc = "If the given subject has multiple descriptions of the same  in , use this field to describe when the given description appears.", },			description = { required = true, type = "content", desc = "The description of the subject.", },			image = { required = true, type = "wiki-page-name", desc = "A wiki file name referring to the image that accompanies the description, if applicable." },		}	} }

return p