More actions
No edit summary |
add |
||
| Line 11: | Line 11: | ||
} | } | ||
function p. | -- str: String to parse | ||
-- delim: String to use to join the book names (default '\n') | |||
function p._appearancesList(str, delim) | |||
if not str then | |||
return '{{error|Syntax: <code>{{#invoke:Book appearances|\'\'string to parse\'\'|\'\'optional delimeter for join function (default newline)\'\'|}}</code>}}' | |||
end | |||
delim = delim or '\n' | delim = delim or '\n' | ||
local res = ''; | local res = ''; | ||
| Line 24: | Line 29: | ||
end | end | ||
return res | return res | ||
end | |||
-- wrapper for _appearancesList, untested | |||
function p.appearancesList(frame) | |||
local args = (frame:getParent() or frame).args | |||
local str = args.str or args[1] | |||
local delim = args.delim or args[2] | |||
return p._appearancesList(str, delim) | |||
end | end | ||
return p | return p | ||
Revision as of 19:40, 16 April 2025
Documentation for this module may be created at Module:Book appearances/doc
-- local string = require("Module:String")
local p = {}
local abbrs = {
["TDP"] = "The Dragonet Prophecy",
["TLH"] = "The Lost Heir",
["THK"] = "The Hidden Kingdom",
["TDS"] = "The Dark Secret",
["TBN"] = "The Brightest Night",
}
-- str: String to parse
-- delim: String to use to join the book names (default '\n')
function p._appearancesList(str, delim)
if not str then
return '{{error|Syntax: <code>{{#invoke:Book appearances|\'\'string to parse\'\'|\'\'optional delimeter for join function (default newline)\'\'|}}</code>}}'
end
delim = delim or '\n'
local res = '';
-- iterate over substrings
for abbr in mw.text.gsplit(str, ' ', true) do
local full = abbrs[abbr]
if full then
res = res .. full .. delim -- concat to result string
else
return '{{error|Unrecognized abbreviation <code>' .. abbr .. '</code>}}'
end
end
return res
end
-- wrapper for _appearancesList, untested
function p.appearancesList(frame)
local args = (frame:getParent() or frame).args
local str = args.str or args[1]
local delim = args.delim or args[2]
return p._appearancesList(str, delim)
end
return p