Module:Term List: Difference between revisions
Jump to navigation
Jump to search
PhantomCaleb (talk | contribs) No edit summary |
PhantomCaleb (talk | contribs) (Undid revision 970850 by PhantomCaleb (Talk)) |
||
Line 22: | Line 22: | ||
else | else | ||
terms = table.concat(terms, ", ") | terms = table.concat(terms, ", ") | ||
end | |||
if args.storeAs then | |||
h.storeSequence(game, args.storeAs, pages) | |||
end | end | ||
Line 33: | Line 36: | ||
for i, page in ipairs(entries) do | for i, page in ipairs(entries) do | ||
local pageEnd = string.find(page, " | local pageEnd = string.find(page, "<") | ||
local additionalInfo = "" | local additionalInfo = "" | ||
if pageEnd then | if pageEnd then | ||
Line 54: | Line 57: | ||
terms[i] = string.gsub(terms[i], [["]], "") | terms[i] = string.gsub(terms[i], [["]], "") | ||
pages[i] = page | pages[i] = page | ||
end | end | ||
Line 63: | Line 63: | ||
function h.storeSequence(game, sequence, pages) | function h.storeSequence(game, sequence, pages) | ||
local seenPages = {} -- prevents duplicates | |||
local seenPages = {} | |||
for i, page in ipairs(pages) do | for i, page in ipairs(pages) do | ||
if not seenPages[page] then | if not seenPages[page] then |
Revision as of 01:26, 13 November 2022
This is the main module for the following templates:
In addition, this module exports the following functions.
termList
termList(game, pages, options)
Returns
- A list the same size as
pages
with Module:Term#printTerm applied to each page. - A list the same size as
pages
with Module:Term#fetchTerm applied to each page. The page name is returned as-is if it stores no terms.
Examples
# | Input | Output | Result | Status | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Link's relatives | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 | termList(
"TWWHD",
{
"Link's Grandma",
"Aryll <small>(little sister)</small>",
},
{ link = true }
)
| {
"[[Link's Grandma#The Wind Waker|Grandma]]",
"[[Aryll#The Wind Waker|Aryll]] <small>(little sister)</small>",
}
| table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{"Grandma", "Aryll"}
| table |
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"
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
if args.storeAs then
h.storeSequence(game, args.storeAs, pages)
end
return terms, categories
end
function p.termList(game, entries, options)
local formattedTerms = {}
local terms = {}
local pages = {}
for i, page in ipairs(entries) 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
formattedTerms[i] = Term.printTerm(page, game, options)..additionalInfo
terms[i] = Term.fetchTerm(page, game, options) or page
terms[i] = string.gsub(terms[i], [['']], "") -- Remove quotes and formatting which may be stored with book terms, e.g. ''Cuccodex''
terms[i] = string.gsub(terms[i], [["]], "")
pages[i] = page
end
return formattedTerms, terms
end
function h.storeSequence(game, sequence, pages)
local seenPages = {} -- prevents duplicates
for i, page in ipairs(pages) do
if not seenPages[page] then
seenPages[page] = true
mw.getCurrentFrame():expandTemplate({
title = "Term List/Store",
args = {
game = game,
sequence = sequence,
subject = page,
ordinality = i,
}
})
end
end
end
function p.Documentation()
return {
termList = {
params = {"game", "pages", "options"},
returns = {
"A list the same size as <code>pages</code> with [[Module:Term#printTerm]] applied to each page.",
"A list the same size as <code>pages</code> with [[Module:Term#fetchTerm]] 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 <small>(little sister)</small>"}, { link = true }},
expect = {
{
"[[Link's Grandma#The Wind Waker|Grandma]]",
"[[Aryll#The Wind Waker|Aryll]] <small>(little sister)</small>",
},
{"Grandma", "Aryll"},
},
},
}
}
}
end
p.Templates = {
["Term List"] = {
purpose = "Applies {{Template|Term}} or {{Template|Plural}} 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 <code>link</code> option of {{Template|Term}} is applied.",
canOmit = true,
},
plural = {
type = "boolean",
desc = "If present, {{Template|Plural}} is used instead of {{Template|Term}}.",
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 [[Special:CargoTables/Sequences|Sequences]] Cargo table for use by [[Template:Sort Value]] and [[Module:Sequences]].",
canOmit = true,
trim = true,
nilIfEmpty = true,
},
}
},
["Term List/Store"] = {
purpose = "Stores in-game sequences that can be used by [[Template:Sort Value]], [[Module:Sequences]], and maybe some day [[Template:Translation Page]].",
storesData = true,
usage = "This template is automatically used via [[Template:Gallery List]] or [[Template:Term List]] when the <code>storeAs</code> 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 = "An article name on the wiki.",
},
ordinality = {
type = "number",
required = true,
desc = "The position of <code>subject</code> in the given sequence.",
},
},
},
}
return p