« Module:Icône » : différence entre les versions

De Les Archives de Vault-Tec
Kharmitch (discussion | contributions)
Aucun résumé des modifications
Kharmitch (discussion | contributions)
mAucun résumé des modifications
 
(3 versions intermédiaires par le même utilisateur non affichées)
Ligne 6 : Ligne 6 :
local DEFAULT_SIZE = 'normal'
local DEFAULT_SIZE = 'normal'
local STANDARD_SIZE = {
local STANDARD_SIZE = {
normal = '14',
normal = '18',
grand  = '20',
grand  = '24',
big    = '20'
big    = '24'
}
}


function buildIcon(args)
function p._build(args)
local name = args[1] or DEFAULT_ICON_NAME
local name = args[1] or DEFAULT_ICON_NAME
local link = args['lien'] or args['link'] or ''
local link = args['lien'] or args['link'] or ''
Ligne 19 : Ligne 19 :
local tooltip = args['infobulle'] or args['tooltip'] or icon.tooltip
local tooltip = args['infobulle'] or args['tooltip'] or icon.tooltip
local size = args[2] or DEFAULT_SIZE
-- Calcul des dimensions
size = STANDARD_SIZE[size] or string.gsub(size, '[px]', '')
local userSize = args[2] or DEFAULT_SIZE
local size = STANDARD_SIZE[userSize]
if not size then
size = userSize:gsub('[px]', '')
size = tonumber(size)
if not size then
size = STANDARD_SIZE[DEFAULT_SIZE]
end
end
return tostring(mw.html.create('span')
return tostring(mw.html.create('span')
:css('cursor', 'help')
:css('cursor', 'help')
:attr('title', tooltip)
:attr('title', tooltip)
:wikitext('[[Fichier:'..filename..'|x'..size..'px|link='..link..']]')
:wikitext('[[Fichier:'..filename..'|'..size..'x'..size..'px|link='..link..'|alt=]]')
:allDone())
:allDone())
end
end
Ligne 56 : Ligne 64 :
     local icon = icons[v]
     local icon = icons[v]
    
    
     doc = doc..'|-\n|<code>'..v..'</code>||[[Fichier:'..icon.filename..'|x20px|link=]]\n'
     doc = doc..'|-\n|<code>'..v..'</code>||[[Fichier:'..icon.filename..'|20x20px|link=]]\n'
     end
     end
      
      
Ligne 65 : Ligne 73 :


function p.build(frame)
function p.build(frame)
return buildIcon(require('Module:Outils').extractArgs(frame))
local args = {}
local argsParent = frame:getParent().args
for cle, val in pairs(argsParent) do
if val then
args[cle] = mw.text.trim(val)
end
end
return p._build(args)
end
end


return p
return p

Dernière version du 31 juillet 2021 à 16:17

La documentation pour ce module peut être créée à Module:Icône/doc

local p = {}

local icons = require('Module:Icône/Données')

local DEFAULT_ICON_NAME = '_DEFAULT'
local DEFAULT_SIZE = 'normal'
local STANDARD_SIZE = {
	normal = '18',
	grand  = '24',
	big    = '24'
}

function p._build(args)
	local name = args[1] or DEFAULT_ICON_NAME
	local link = args['lien'] or args['link'] or ''
	
	local icon = icons[name:lower()] or icons[DEFAULT_ICON_NAME]
	local filename = icon.filename
	local tooltip = args['infobulle'] or args['tooltip'] or icon.tooltip
	
	-- Calcul des dimensions
	local userSize = args[2] or DEFAULT_SIZE
	local size = STANDARD_SIZE[userSize]
	if not size then
		size = userSize:gsub('[px]', '')
		size = tonumber(size)
		if not size then
			size = STANDARD_SIZE[DEFAULT_SIZE]
		end
	end
	
	return tostring(mw.html.create('span')
		:css('cursor', 'help')
		:attr('title', tooltip)
		:wikitext('[[Fichier:'..filename..'|'..size..'x'..size..'px|link='..link..'|alt=]]')
		:allDone())
end

--[[
	Fonction utilisée dans la doc du modèle pour présenter
	les cônes disponibles aux contributeurs
]]
function p.doc()
	local tabDefinition = '{| class="va-table va-table-center-col2" style="float:left;margin-right:4px;width:250px;"\n!style="width:70%;"|mot-clé!!style="width:30%;"|icône\n'
	local doc = tabDefinition

	keywords = {}
    for k in pairs(icons) do
        table.insert(keywords, k)
    end
    table.sort(keywords)
    
    local split = math.ceil(#keywords / 3)
    local n = 0
    
    for k, v in ipairs(keywords) do
    	if n > split then
    		doc = doc..'\n|}'
    		doc = doc..'\n'..tabDefinition
    		n = 0
    	end
    	
    	n = n + 1
    	local icon = icons[v]
    	
    	doc = doc..'|-\n|<code>'..v..'</code>||[[Fichier:'..icon.filename..'|20x20px|link=]]\n'
    end
    
    doc = doc..'|}'

	return doc
end

function p.build(frame)
	local args = {}
	
	local argsParent = frame:getParent().args
	for cle, val in pairs(argsParent) do
		if val then
			args[cle] = mw.text.trim(val)
		end
	end
	
	return p._build(args)
end

return p