We have begun migration of most wikis to our new host, Amazon Web Services. All but the top 100 wikis are in read-only mode until the migration is complete. Estimated completion: TBD -- Update: Fri 10/20 11pm UTC - We have encountered some unexpected issues. Our staff is working around the clock to complete this process as quickly as possible. Thank you for your patience.

Module:Image : Différence entre versions

De Binding of Isaac: Rebirth Wiki
Aller à : navigation, rechercher
(Erreur : args.pfx et args.sfx rajoutent un espace insécable)
(Simplification)
 
(16 révisions intermédiaires par le même utilisateur non affichées)
Ligne 42 : Ligne 42 :
 
function p.main( f, default )
 
function p.main( f, default )
 
local args = rtext.trimAll( rtext.getArgs( f ) )
 
local args = rtext.trimAll( rtext.getArgs( f ) )
 +
if not args.params then error( "Ce module nécessite une transclusion.", 0 ) end
 +
 
local ret = ''
 
local ret = ''
 
local userParams = splitImages( args.params )
 
local userParams = splitImages( args.params )
if args.image1 then
+
for i, j in pairs( userParams ) do
local params = {}
+
ret = ret .. p.data( args['image'..i] and merge( j, splitParams( args['image'..i] ) ) or j )
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
 
end
 
return ret
 
return ret
Ligne 65 : Ligne 57 :
 
 
 
local dataNameValue = { name=args.name, data=true }
 
local dataNameValue = { name=args.name, data=true }
if args.type then
+
dataNameValue.type = args.type or nil
dataNameValue.type = args.type
+
local dataName = rtext.link( dataNameValue ).clean
 +
local fileName = ''
 +
if args.fullname then
 +
fileName = args.fullname
 +
else
 +
if args.pfx then fileName = ( args.pfx ):lower() .. ' ' end
 +
fileName = fileName .. dataName
 +
if args.sfx then fileName = ' ' .. ( args.sfx ):lower() end
 
end
 
end
local dataName = rtext.link( dataNameValue ).clean
 
local fileName = args.fullname or ( args.pfx .. ' ' or '' ):lower() .. dataName .. ( ' ' .. args.sfx or '' ):lower()
 
 
 
 
local fileExt = '.' .. ( args.ext or 'png' )
 
local fileExt = '.' .. ( args.ext or 'png' )
Ligne 103 : Ligne 100 :
 
end
 
end
 
 
return '[[Image:' .. fileName .. fileExt .. '|' .. fileSize .. '|' .. fileAlign .. '|link=' --[[.. fileLink]] .. ']]'
+
return '[[Image:' .. fileName .. fileExt .. '|' .. fileSize .. 'px|' .. fileAlign .. '|link=' .. fileLink .. ']]'
 
end
 
end
  
 
return p
 
return p

Version actuelle datée du 17 octobre 2017 à 19:14

Missing No. Icon.png
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é.



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 ) )
	if not args.params then error( "Ce module nécessite une transclusion.", 0 ) end
	
	local ret = ''
	local userParams = splitImages( args.params )
	for i, j in pairs( userParams ) do
		ret = ret .. p.data( args['image'..i] and merge( j, splitParams( args['image'..i] ) ) or j )
	end
	return ret
end


function p.data( f )
	local args = rtext.trimAll( rtext.getArgs( f ) )
	
	local dataNameValue = { name=args.name, data=true }
	dataNameValue.type = args.type or nil
	local dataName = rtext.link( dataNameValue ).clean
	local fileName = ''
	if args.fullname then
		fileName = args.fullname
	else
		if args.pfx then fileName = ( args.pfx ):lower() .. ' ' end 
		fileName = fileName .. dataName
		if args.sfx then fileName = ' ' .. ( args.sfx ):lower() end
	end
	
	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 args.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 * scale ) .. 'x' .. math.ceil( size.height * scale )
	
	local fileAlign = args.align or 'center'
	
	local fileLink = ''
	if args.link == 'true' then
		fileLink = rtext.link({ name=args.name, data=true }).name .. '|' .. rtext.link({ name=args.name, data=true }).name
	end
	
	return '[[Image:' .. fileName .. fileExt .. '|' .. fileSize .. 'px|' .. fileAlign .. '|link=' .. fileLink .. ']]'
end

return p