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 rtext = require( 'Module:Text' )
-- Split parameters string, e.g.: "ext: gif, size:12" --> { ext = "gif", size = "12" }
local function splitParams( initialString )
local firstSplit = rtext.trimAll( mw.text.split( initialString, ',%s' ) )
local param = {}
local allParam = {}
for i, j in pairs( firstSplit ) do
param = rtext.trimAll( mw.text.split( j, ':' ) )
allParam[param[1]] = param[2]
end
return allParam
end
-- Split images string, e.g.: "(ext: gif, size:12 )(name:Box)" --> { 1 = "ext: gif, size:12", 2 = "name:Box" }
local function splitImages( initialString )
local images = rtext.trimAll( rtext.trimAll( mw.text.split( initialString, '%(' ) ), '%)' )
local params = {}
local i = 2 -- 1st box of 'images' is empty
repeat
params[i-1] = splitParams( images[i] )
i = i + 1
until not images[i]
return params
end
local function merge( userParam, default )
local param = {}
for i, j in pairs( default ) do
param[i] = j
end
for k, l in pairs( userParam ) do
param[k] = l
end
return param
end
function p.main( f, default )
local args = rtext.trimAll( rtext.getArgs( f ) )
local ret = ''
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] ) )
end
--[[else
ret = ret .. p.data( allParam )]]
end
return ret
end
function p.data( f )
local args = rtext.trimAll( rtext.getArgs( f ) )
local dataNameValue = { name=args.name, data=true }
if args.type then
dataNameValue.type = args.type
end
local dataName = rtext.link( dataNameValue ).clean
local fileName = args.fullname or args.pfx:lower() .. ' ' .. dataName .. ' ' .. args.sfx:lower()
--[[local fileExt = '.' .. ( args.ext or 'png' )
local size = { width = args.width, height = args.height }
if args.type then
for i, j in pairs( mw.loadData( 'Module:Data' ).imageSize[args.type] ) do
if dataName == i then
if args.id then
for k, l in pairs( j ) do
if id:lower() == k then
size.width = l[1]
size.height = l[2]
break
end
end
else
size.width = j[1][1]
size.height = j[1][2]
end
break
end
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 dataName--'[[Image:' .. fileName .. fileExt '|' .. fileSize .. '|' .. fileAlign .. '|link=' .. fileLink .. ']]'
end
return p