Module:Term List

local p = {} local h = {}

local Franchise = require("Module:Franchise") local Term = require("Module:Term") local utilsArg = require("Module:UtilsArg") local utilsMarkup = require("Module:UtilsMarkup") local utilsString = require("Module:UtilsString")

function p.Main(frame) local args, err = utilsArg.parse(frame:getParent.args, p.Templates["Term List"]) local categories = err and err.categoryText or "" local pages = args.pages or {} local game = args.game or "Series" if args.storeAs then h.storeSequence(frame, game, args.storeAs, pages) end local terms = p.termList(game, pages, args) if args.listType == "bullet" then terms = utilsMarkup.bulletList(terms) elseif args.listType == "plain" then terms = utilsMarkup.list(terms) else terms = table.concat(terms, ", ") end return terms, categories end

function p.termList(game, pages, options) local terms = {} local rawTerms = {} for i, page in ipairs(pages) do		local pageEnd = string.find(page, "<") local additionalInfo = "" if pageEnd then additionalInfo = string.sub(page, pageEnd, #page) page = string.sub(page, 1, pageEnd - 1) if utilsString.endsWith(page, " ") then page = utilsString.trim(page) additionalInfo = " "..additionalInfo end end local pageInput = page page = mw.text.unstrip(page) if page ~= pageInput then additionalInfo = additionalInfo..string.gsub(pageInput, page, "") end terms[i] = Term.printTerm(page, game, options)..additionalInfo rawTerms[i] = Term.fetchTerm(page, game, options) or page end

return terms, rawTerms end

function h.storeSequence(frame, game, sequence, pages) for i, page in ipairs(pages) do		frame:expandTemplate({			title = "Term List/Store",			args = {				game = game,				sequence = sequence,				subject = page,				ordinality = i,			}		}) end end

function p.Documentation return { termList = { params = {"game", "pages", "options"}, returns = { "A list the same size as  with Module:Term applied to each page.", "A list the same size as  with Module:Term applied to each page. The page name is returned as-is if it stores no terms.", },			cases = { {					desc = "Link's relatives", args = {"TWWHD", {"Link's Grandma", "Aryll (little sister) "}, { link = true }}, expect = { {							"Grandma", "Aryll (little sister) ", },						{"Grandma", "Aryll"}, },				},			}		}	} end

p.Templates = { ["Term List"] = { purpose = "Applies or  to a list of page names.", paramOrder = {1, 2, "link", "plural", "listType", "storeAs"}, params = { [1] = {				name = "game", required = true, enum = Franchise.enum({ includeSeries = true }), type = "string", desc = "A game code.", nilIfEmpty= true, },			[2] = {				name = "pages", required = true, type = "content", desc = "Comma-separated list of wiki page names.", trim = true, nilIfEmpty= true, split = true, },			link = { type = "boolean", desc = "If present, the  option of  is applied.", canOmit = true, },			plural = { type = "boolean", desc = "If present, is used instead of .", canOmit = true, },			listType = { type = "string", enum = {"bullet", "comma", "plain"}, default = "comma", desc = "Sets the list formatting.", canOmit = true, },			storeAs = { type = "string", desc = "Stores the list in the Sequences Cargo table for use by Template:Sort Value.", canOmit = true, trim = true, nilIfEmpty = true, },		}	},	["Term List/Store"] = { purpose = "Stores in-game sequences that can be used by Template:Sort Value or Module:Sort.", storesData = true, usage = "This template is automatically used via Template:Term List when the  parameter is set.", paramOrder = {"game", "sequence", "subject", "ordinality"}, params = { game = { type = "string", required = true, desc = "A game code from Data:Franchise.", },			sequence = { type = "string", required = true, desc = "A sequence name.", },			subject = { type = "wiki-page-name", required = true, desc = "The name of a page on the wiki.", },			ordinality = { type = "number", required = true, desc = "The position of  in the given sequence.", },		},	}, }

return p