(Essai) |
(Combo) |
||
(76 versions intermédiaires par le même utilisateur non affichées) | |||
Ligne 1 : | Ligne 1 : | ||
local p = {} |
local p = {} |
||
− | local |
+ | local tableau = require( 'Module:Tableau' ) |
− | -- |
+ | -- "ext: gif, taille:12" --> { ext = "gif", taille = "12" } |
− | + | function p.separerParams( chaineInitiale ) |
|
− | local |
+ | local premiereSeparation = tableau.toutRogner( mw.text.split( chaineInitiale, ',%s' ) ) |
local param = {} |
local param = {} |
||
− | local |
+ | local tousParams = {} |
− | for i, j in pairs( |
+ | for i, j in pairs( premiereSeparation ) do |
− | + | if j:find( ':' ) then |
|
+ | param = tableau.toutRogner( mw.text.split( j, ':' ) ) |
||
− | + | tousParams[param[1]] = param[2] |
|
⚫ | |||
+ | tousParams[1] = j |
||
⚫ | |||
end |
end |
||
− | return |
+ | return tousParams |
end |
end |
||
− | -- |
+ | -- "( ext: gif, taille:12 )(nom : Case)" --> { 1 = "ext: gif, taille:12", 2 = "nom : Case" } |
− | + | function p.separerImages( chaineInitiale ) |
|
− | local images = |
+ | local images = tableau.toutRogner( tableau.toutRogner( mw.text.split( chaineInitiale, '%(' ) ), '%)' ) |
local params = {} |
local params = {} |
||
− | local i = 2 -- |
+ | local i = 2 -- 1ère case de 'images' est vide |
repeat |
repeat |
||
− | params[i-1] = |
+ | params[i-1] = p.separerParams( images[i] ) |
i = i + 1 |
i = i + 1 |
||
until not images[i] |
until not images[i] |
||
Ligne 28 : | Ligne 32 : | ||
− | local function |
+ | local function fusionner( paramUtilisateur, default ) |
local param = {} |
local param = {} |
||
for i, j in pairs( default ) do |
for i, j in pairs( default ) do |
||
param[i] = j |
param[i] = j |
||
end |
end |
||
− | for k, l in pairs( |
+ | for k, l in pairs( paramUtilisateur ) do |
param[k] = l |
param[k] = l |
||
end |
end |
||
Ligne 40 : | Ligne 44 : | ||
− | function p.main( f |
+ | function p.main( f ) -- fonction dépréciée |
⚫ | |||
⚫ | |||
⚫ | |||
− | local userParams = splitImages( args.params ) |
||
− | if args.image1 then |
||
− | local params = {} |
||
− | local i = 1 |
||
− | repeat |
||
− | params[i] = splitParams( args['image'..i] ) |
||
− | i = i + 1 |
||
− | until not args['image'..i] |
||
− | for k, l in pairs( userParams ) do |
||
− | ret = ret .. p.data( merge( l, params[k] ) ) |
||
⚫ | |||
− | --[[else |
||
− | ret = ret .. p.data( allParam )]] |
||
⚫ | |||
⚫ | |||
end |
end |
||
⚫ | |||
− | |||
⚫ | |||
⚫ | |||
+ | if not args.params then error( 'Paramètre "params" manquant', 0 ) end |
||
⚫ | |||
⚫ | |||
− | local dataNameValue = { name=args.name, data=true } |
||
+ | for i, j in pairs( p.separerImages( args.params ) ) do |
||
− | if args.type then |
||
+ | renvoi = renvoi .. p.donnees( args['par défaut'] and fusionner( args['image'..i] and fusionner( j, p.separerParams( args['image'..i] ) ) or j, p.separerParams( args['par défaut'] ) ) or args['image'..i] and fusionner( j, p.separerParams( args['image'..i] ) ) or j ) |
||
− | dataNameValue.type = args.type |
||
end |
end |
||
− | local dataName = rtext.link( dataNameValue ).clean |
||
− | local fileName = args.fullname or ( args.pfx or '' ):lower() .. ' ' .. dataName .. ' ' .. ( args.sfx or '' ):lower() |
||
+ | return renvoi |
||
⚫ | |||
⚫ | |||
− | |||
+ | |||
− | local size = { width = args.width, height = args.height } |
||
+ | |||
− | if args.type then |
||
+ | function p.donnees( f ) |
||
− | for i, j in pairs( mw.loadData( 'Module:Data' ).imageSize[args.type] ) do |
||
⚫ | |||
− | --[[if dataName == i then |
||
⚫ | |||
− | if args.id then |
||
+ | return '[[' .. nomFichier .. '|' .. math.ceil( ( args.largeur or mw.getCurrentFrame():callParserFunction( '#imgw', nomFichier ) ) * ( args['échelle'] or 1 ) ) .. 'x' .. math.ceil( ( args.hauteur or mw.getCurrentFrame():callParserFunction( '#imgh', nomFichier ) ) * ( args['échelle'] or 1 ) ) .. 'px|' .. ( args.alignement or '' ) .. '|lien=' .. ( args.lien or '' ) .. '|' .. ( args.desc or '' ) .. ']]' |
||
− | for k, l in pairs( j ) do |
||
− | if id:lower() == k then |
||
− | size.width = l[1] |
||
− | size.height = l[2] |
||
− | break |
||
− | end |
||
− | end |
||
⚫ | |||
− | size.width = j[1][1] |
||
− | size.height = j[1][2] |
||
− | end |
||
− | break |
||
− | end]]size.width = 'aaa' |
||
− | end |
||
− | end |
||
− | --[[local scale = args.scale or '1' |
||
− | local fileSize = math.ceil( size.width * args.scale ) .. 'x' .. math.ceil( size.height * args.scale ) |
||
− | |||
− | local fileAlign = args.align or 'center' |
||
− | |||
− | local fileLink = rtext.link({ name=args.name, data=true }).name .. '|' .. rtext.link({ name=args.name, data=true }).name]] |
||
− | |||
− | return size.width --.. 'x' .. size.height--'[[Image:' .. fileName .. fileExt '|' .. fileSize .. '|' .. fileAlign .. '|link=' .. fileLink .. ']]' |
||
end |
end |
||
Dernière version du 20 février 2019 à 14:28
Ce module est lié au projet Modèles. Ne l'utilisez pas sur des pages du wiki non-liées à ce projet tant que celui-ci n'est pas terminé.
|
La documentation ci-haut est transcluse de Module:Image/doc. (modifier | historique)
local p = {}
local tableau = require( 'Module:Tableau' )
-- "ext: gif, taille:12" --> { ext = "gif", taille = "12" }
function p.separerParams( chaineInitiale )
local premiereSeparation = tableau.toutRogner( mw.text.split( chaineInitiale, ',%s' ) )
local param = {}
local tousParams = {}
for i, j in pairs( premiereSeparation ) do
if j:find( ':' ) then
param = tableau.toutRogner( mw.text.split( j, ':' ) )
tousParams[param[1]] = param[2]
else
tousParams[1] = j
end
end
return tousParams
end
-- "( ext: gif, taille:12 )(nom : Case)" --> { 1 = "ext: gif, taille:12", 2 = "nom : Case" }
function p.separerImages( chaineInitiale )
local images = tableau.toutRogner( tableau.toutRogner( mw.text.split( chaineInitiale, '%(' ) ), '%)' )
local params = {}
local i = 2 -- 1ère case de 'images' est vide
repeat
params[i-1] = p.separerParams( images[i] )
i = i + 1
until not images[i]
return params
end
local function fusionner( paramUtilisateur, default )
local param = {}
for i, j in pairs( default ) do
param[i] = j
end
for k, l in pairs( paramUtilisateur ) do
param[k] = l
end
return param
end
function p.main( f ) -- fonction dépréciée
return p.pcpl( f )
end
function p.pcpl( f )
local args = tableau.toutRogner( tableau.obtenirArgs( f ) )
if not args.params then error( 'Paramètre "params" manquant', 0 ) end
local renvoi = ''
for i, j in pairs( p.separerImages( args.params ) ) do
renvoi = renvoi .. p.donnees( args['par défaut'] and fusionner( args['image'..i] and fusionner( j, p.separerParams( args['image'..i] ) ) or j, p.separerParams( args['par défaut'] ) ) or args['image'..i] and fusionner( j, p.separerParams( args['image'..i] ) ) or j )
end
return renvoi
end
function p.donnees( f )
local args = tableau.toutRogner( tableau.obtenirArgs( f ) )
local nomFichier = 'Image:' .. args.nom .. '.' .. ( args.ext or 'png' )
return '[[' .. nomFichier .. '|' .. math.ceil( ( args.largeur or mw.getCurrentFrame():callParserFunction( '#imgw', nomFichier ) ) * ( args['échelle'] or 1 ) ) .. 'x' .. math.ceil( ( args.hauteur or mw.getCurrentFrame():callParserFunction( '#imgh', nomFichier ) ) * ( args['échelle'] or 1 ) ) .. 'px|' .. ( args.alignement or '' ) .. '|lien=' .. ( args.lien or '' ) .. '|' .. ( args.desc or '' ) .. ']]'
end
return p