Differenze tra le versioni di "Modulo:PokePrecSucc"

Better solution to support subpages *** sovrascritto il testo esistente ***
(Adding support for subpages *** sovrascritto il testo esistente ***)
(Better solution to support subpages *** sovrascritto il testo esistente ***)
Navigation bar with previous and next Pokémon in dex order.
 
This module exports two functions.
It is also possible to use this module to add a PrevNext to a subpage of a
Pokémon page. ThisOne is the default"PokePrecSucc", behaviourintended whento be used inwithin a subpage:Pokémon itpages, takesthat
links the previous and next Pokémon pages.
the name of the root page and links to the corresponding subpages. This
The other is "subpage", intended to be used in Pokémon subpages to link
behaviour can be suppressed giving the parameter "nosubpage", or using
corresponding subpages of previous and next Pokémon.
the parameter "subpage" to specify the title of the subpage to link.
 
Usage:
 
{{#invoke: PokePrecSucc | PokePrecSucc | <Pokémon name> | other args }}
 
- 1: (optional) is the name of a Pokémon. In a Pokémon page or subpage
the suggested value for this is "{{ROOTPAGENAME}}", that evaluates to
the page name that (often) is the Pokémon name desired. If not given,
it takes the root page title.
- nosubpage: (optional) if this parameter is "yes" it suppress the link to
subpages, linking the root page instead.
- subpage: (optional) if given, it is used to determine the subpage to
link instead of using the current page subpage title. It should be the
name of the subpage to link without the leading /.
 
--]]
--[[
 
Base (internal) function to create a PokePrecSucc. Performs basic operations
This function computes the subpage suffix to append to links.
such as computing previous and next Pokémon ndex, and preparing the printed
text.
 
Parameters:
It's only parameter is the frame.args given to the module's invoke.
- poke: the Pokémon name
- linksuffix: (optional) the suffix to append to links. If not given
defaults to nothing (ie: links base Pokémon pages). This suffix is
appended as is; it's not modified, for instance, adding a leading "/".
 
--]]
local function getSubpageLinkbasePokePrecSucc(argspoke, linksuffix)
linksuffix = linksuffix or ""
if string.trim(args.nosubpage) == "yes" then
return ""
end
if args.subpage then
return "/" .. string.trim(args.subpage)
end
local title = mw.title.getCurrentTitle()
if title.isSubpage then
return "/" .. mw.title.getCurrentTitle().subpageText
end
return ""
end
 
m.PokePrecSucc = function(frame)
local poke = string.trim(frame.args[1]
or mw.title.getCurrentTitle().rootText):lower()
local pokeData = multigen.getGen(pokes[poke] or pokes[mw.text.decode(poke)])
local type1, type2 = pokeData.type1, pokeData.type2
local prevTf, nextTf = string.tf(prev), string.tf(next)
local prevname, nextname = pokes[prev].name, pokes[next].name
local linksuffix = getSubpageLink(frame.args)
return prevnext.PrevNextLua{
color = type1,
nextspr = nextTf,
}
end
 
--[[
 
Function to create a PrecSucc of subpages.
 
Usage:
{{#invoke: PokePrecSucc | subpage | <Pokémon name> | <suffix> }}
 
- 1: (optional) is the name of a Pokémon. In a Pokémon pagesubpage orthe subpagesuggested value
the suggested value for this is "{{ROOTPAGENAME}}", that evaluates to the page name that
the page name that (often) is the Pokémon name desired. If not given, it defaults to the root
page title.
- subpage2: (optional) if given, it is used to determine the subpage to link. It
should be the name of the subpage to link without the leading /. If not
given, it defaults to the same suffix as the page it's invoked in.
 
--]]
m.subpage = function(frame)
local poke = string.trim(frame.args[1]
or mw.title.getCurrentTitle().rootText):lower()
local subpageSuffix = ""
if argsframe.subpageargs[2] then
returnsubpageSuffix = "/" .. string.trim(argsframe.subpageargs[2])
endelse
local title = mw.title.getCurrentTitle()
if title.isSubpage then
return subpageSuffix = "/" .. mw.title.getCurrentTitle().subpageText
return ""end
end
 
return basePokePrecSucc(poke, subpageSuffix)
end
 
--[[
 
Function to create a PrecSucc in a Pokémon page.
 
Usage:
{{#invoke: PokePrecSucc | PokePrecSucc | <Pokémon name> | other args }}
 
- 1: (optional) the name of a Pokémon. In a Pokémon the suggested value for
this is "{{PAGENAME}}", that evaluates to the page name that (often) is
the Pokémon name desired. If not given, it defaults to the page title.
 
--]]
m.PokePrecSucc = function(frame)
local linksuffixpoke = getSubpageLinkstring.trim(frame.args)[1]
or mw.title.getCurrentTitle().text):lower()
return basePokePrecSucc(poke)
end
 
79 548

contributi