Module:Infobox/Hexasoft
Apparence
[voir] [modifier] [historique] [purger]
Cette page définit un module d'infobox.
La documentation de ce module est générée par le modèle {{Documentation module}}.
Elle est incluse depuis la page Modèle:Documentation module d'infobox. Veuillez placer les catégories sur cette page-là.
Les éditeurs peuvent travailler dans le bac à sable (créer).
Voir les statistiques d'appel depuis le wikicode sur l'outil wstat et les appels depuis d'autres modules.
--[[
Ceci est un test, qui sera supprimé.
--]]
local localdata = require "Module:Infobox/Localdata"
local italiques = require "Module:Italiques biologiques"
local data = require "Module:Taxobox données"
-- debug
local function build()
local out = ""
for _, v in pairs(localdata) do
out = out .. _ .. " " .. v .. "<br/>"
end
return out
end
local function mytrim(val)
if (val == nil) then
return ""
end
return mw.text.trim(val)
end
-- retourne une table de classification à partir des données et d'une position de départ
local function sub_classification(pos)
local out = {}
local i = pos
local dg = "+ "
-- on cherche le premier 'rang'
while(true) do
if ((localdata[i] == nil) or (mw.text.trim(localdata[i]) == 'fin classification')) then
return nil, dg -- pas trouvé !
end
if (mw.text.trim(localdata[i]) == 'rang') then
break -- trouvé
end
i = i + 1
end
while(true) do
dg = dg .. " ." .. i
if ((localdata[i] == nil) or (mw.text.trim(localdata[i]) == 'fin classification')) then
dg = dg .. " end"
break
end
if (mw.text.trim(localdata[i]) == 'rang') then
local res = {}
res['rang'] = mytrim(localdata[i+1]) or "inconnu"
res['taxon'] = mytrim(localdata[i+2]) or "erreur"
dg = dg .. " add " .. res['rang'] .. "+" .. res['taxon']
local buf = mytrim(localdata[i+3])
if ((buf ~= "") and (buf ~= 'rang') and (buf ~= 'fin classification')) then
res['affiche'] = buf
i = i + 1
dg = dg .. " add r+t+a"
end
i = i + 3
dg = dg .. " insert"
table.insert(out, res)
else
dg = dg .. " !rang (" .. localdata[i] .. ")"
break
end
end
if (next(out) == nil) then
return nil, dg
end
return out, dg
end
-- parcours les données pour trouver la classification
local function classification(num)
local out = nil
local classif = nil
local tmp = nil
local dg = "x"
local ddg = ">> "
local cur = 0
num = num or 0 -- num → passe les 'num' premières trouvées
for i, _v in pairs(localdata) do
if (type(i) == "number") then
dg = dg .. " " .. i .. "/" .. _v
v = mw.text.trim(_v)
if (v == 'classification') then
dg = dg .. " =classif"
if (cur >= num) then
dg = dg .. " =sub_classif"
tmp, ddg = sub_classification(i+1)
cur = cur + 1
end
break
end
end
end
-- mise en forme des données
if (tmp == nil) then
return {type='table',titlestyle={['background-color']='#FFE4C4'},
title='NIL',rows={{type='row1col',value=dg .. "<br/>" .. ddg}}}
end
out = {
type = 'table',
title = 'Classification',
titlestyle = {['background-color']='#FFE4C4'},
}
local cnt = 0
rows = {}
-- si besoin : ajout du "règne"
if (data.regnes[localdata['charte']]['règne auto'] ~= nil) then
local rg = data.regnes[localdata['charte']]['règne auto']
local tmp
if (data.rangs[rg[1][1]]) then
tmp = data.rangs[rg[1][1]]['wikif']
else
tmp = data.rangs['inconnu']['wikif']
end
localdata[num .. "-v-classif-R"] =
italiques.italique_biologique("[[" .. rg[1][2] .. "]]", rg[1][1], localdata["charte"])
table.insert(rows, {type = 'row', label = tmp, value = num .. "-v-classif-R" })
end
for i, v in ipairs(tmp) do
local tmp
if (data.rangs[v['rang']]) then
tmp = data.rangs[v['rang']]['wikif']
else
tmp = data.rangs['inconnu']['wikif']
end
local x = { type = 'row', label = tmp, value = num .. "-v-classif-" .. cnt }
dg = dg .. " SET(" .. v['rang'] .. ") " .. num .. "-v-classif-" .. cnt .. "=" .. v['taxon']
if (v['affiche'] == nil) then
localdata[num .. "-v-classif-" .. cnt] =
italiques.italique_biologique("[[" .. v['taxon'] .. "]]", v['rang'], localdata["charte"])
table.insert(rows, x)
else
localdata[num .. "-v-classif-" .. cnt] =
italiques.italique_biologique("[[" .. v['taxon'] .. "|" .. v['affiche'] .. "]]", v['rang'], localdata["charte"])
table.insert(rows, x)
end
cnt = cnt + 1
end
-- table.insert(rows, {type='row',label=cnt,value='taxon'})
-- table.insert(rows, {type='row1col',value=dg .. "<br/>" .. ddg})
out['rows'] = rows
return out
end
local function synonymes()
local out = nil
if (localdata['synonymes']) then
out = {
type = 'table',
title = '[[Synonyme (taxinomie)|Synonymes]]',
titlestyle = {['background-color']='#FFE4C4'},
rows = {
{ type = 'row1col', value = "\n" .. localdata['synonymes'] },
},
}
end
return out
end
function cites()
local out = nil
for i, _v in pairs(localdata) do
if ((type(i) == "number") and (type(_v) == "string")) then
v = mw.text.trim(_v)
if (v == "cites") then
tmp = localdata[i+1]
out = {
type = 'table',
title = 'Statut [[Convention sur le commerce international des espèces de faune et de flore sauvages menacées d\'extinction|CITES]]',
titlestyle = {['background-color']='#FFE4C4'},
rows = {
{ type = 'row1col', value = tmp, },
},
}
end
end
end
return out
end
function iucn()
local out = nil
for i, _v in pairs(localdata) do
if ((type(i) == "number") and (type(_v) == "string")) then
v = mw.text.trim(_v)
if (v == "iucn") then
tmp = localdata[i+1]
out = {
type = 'table',
title = '[[Statut de conservation]] [[Union internationale pour la conservation de la nature|UICN]]',
titlestyle = {['background-color']='#FFE4C4'},
rows = {
{ type = 'row1col', value = tmp, },
},
}
end
end
end
return out
end
local function genere()
local out = {}
localdata["taxon-mef"] = italiques.italique_biologique(localdata["taxon"], localdata["rang"], localdata["charte"])
-- localdata["taxon"] : il faut le mettre en forme (italiques…)
localdata["val1"] = "valeur 1"
localdata["val2"] = "valeur 2"
localdata["val3"] = "valeur 3"
localdata["debug"] = build()
out = {
maincolor = '#FFA07A',
-- secondcolor = '#FF0000',
parts = {
{
type = 'title',
value = 'taxon-mef',
},
{
type = 'images',
imageparameters = 'image',
captionparameter = 'légende',
defaultimage = 'Defaut 2.svg',
},
classification(0),
{
type = 'table',
titlestyle={['background-color']='#FFE4C4'},
title = data.rangs[localdata['rang']]["wikif long"],
rows = {
{ type = 'row1col', value = localdata["taxon-mef"] },
{ type = 'row1col', value = localdata["auteur"] },
},
},
synonymes(),
iucn(),
cites(),
-- {
-- type = 'table',
-- title = 'Debug',
-- rows = {
-- { type = 'row1col', value = localdata["debug"] },
-- },
-- },
}
}
return out
end
return genere()