Aller au contenu

Module:Infobox/Hexasoft

Une page de Wikipédia, l'encyclopédie libre.
Ceci est une version archivée de cette page, en date du 30 avril 2019 à 13:02 et modifiée en dernier par Hexasoft (discuter | contributions). Elle peut contenir des erreurs, des inexactitudes ou des contenus vandalisés non présents dans la version actuelle.

 Documentation[voir] [modifier] [historique] [purger]

Cette page définit un module d'infobox.


--[[
  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 = {}
	
	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


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"] },
				},
			},
			{
				maincolor = '#00FFFF',
				type = 'table',
				title = 'Table',
				rows = {
					{ type = 'row', label = 'label 1', value = 'val1' },
					{ type = 'row', label = 'label 2', value = 'val2' },
				},
			},
			{
				type = 'table',
				title = 'Entrée',
				rows = {
					{ type = 'row1col', value = localdata["val3"] },
				},
			},
		}
	}
	
	return out
end
	

return genere()