Module:Sandbox/Tiddlywinks
Documentation for this module may be created at Module:Sandbox/Tiddlywinks/doc
local p = {}
-- A simple re-implementation of the v template as a module
-- [[Pokémon {{{1}}} Version{{{2|}}} {{{3|}}}|{{{1}}} Version{{{2|}}}{{#if:{{{3|}}}| {{{3|}}}}}]]
function p.v(frame)
local pf = frame:getParent().args -- This line allows template parameters to be used in this code easily
local f = frame.args -- This line allows parameters from {{#invoke:}} to be used easily
local game = pf[1] or f[1]
local plural = pf[2] or f[2]
if plural == nil then
plural = ""
end
local numeral = pf[3] or f[3]
local link = "Pokémon " .. game .. " Version" .. plural
local text = game .. " Version" .. plural
if numeral ~= nil then
link = link .. " " .. numeral
text = text .. " " .. numeral
end
return "[[" .. link .. "|" .. text .. "]]"
end
-- A re-implementation of the v template that only uses one parameter (auto-detecting the other options)
function p.vauto(frame)
local pf = frame:getParent().args -- This line allows template parameters to be used in this code easily
local f = frame.args -- This line allows parameters from {{#invoke:}} to be used easily
local game = pf[1] or f[1]
local link = "Pokémon " .. game .. " Version"
local text = game .. " Version"
if game == "Black 2 and White 2" then
-- For B2W2, we're just gonna redo the whole thing
link = "Pokémon Black and White Versions 2"
text = "Black and White Versions 2"
else
-- For all other cases, add an "s" if there are multiple games
if string.find( game, " and " ) ~= nil then
link = link .. "s"
text = text .. "s"
end
end
return "[[" .. link .. "|" .. text .. "]]"
end
return p
Categories
- No categories associated with this article