Module:Hello world2

From Wikipedia

Documentation for this module may be created at Module:Hello world2/doc

local p = {}

function p.main(frame)
	local args = {}
	local argsParent = frame:getParent().args

	--Paramètres vides interprétés par Lua
	for cle, val in pairs(argsParent) do
		if val ~= '' then
			--args[cle] = mw.text.trim(val)
			args[mw.ustring.lower(cle)] = mw.text.trim(val)
		end
	end

	return p._main(args)
end

function p._main(args)
	local res = mw.html.create('div')
	local fichierWiki = '[[Fichier:%s|%spx|link=%s|%s|alt=%s]]'

	res
		:addClass('icone_de_titre')
		--:css('display', 'none')
		:css('float', 'right')
		:css('margin-top', '1em')
		:tag('span')
			:attr('title', args.texte or 'Exemple de texte')
			:wikitext(mw.ustring.format(fichierWiki,
				args.image or 'Fairytale bookmark.png',
				args.taille or 20,
				args.lien or 'Modèle:Icône de titre',
				args['paramètre'] or '',
				args.texte or 'Exemple de texte'))

	return tostring(res)
end

--Bibliothèque utile
function gestionArgs(frame)
	local args = {}
	local argsParent = frame:getParent().args

	--Paramètres vides interprétés par Lua
	for cle, val in pairs(argsParent) do
		if val ~= '' then
			args[cle] = mw.text.trim(val)
		end
	end

	return args
end

function erreur(texte)
    return tostring(mw.html.create('span'):addClass('error'):wikitext(texte))
end

local format = mw.ustring.format

function lienWiki(lien, titre)
	if titreLien then return format('[[%s|%s]]', lien, titre) end
	return format('[[%s]]', lien)
end

function lienUrl(lien, titre)
	return format('[http://%s %s]', lien, titre)
end

local function makeWrapper(protectionType)
	return function (frame)
		-- If called via #invoke, use the args passed into the invoking template, or the args passed to #invoke if any exist.
		-- Otherwise assume args are being passed directly in from the debug console or from another Lua module.
		local origArgs
		if frame == mw.getCurrentFrame() then
			origArgs = frame:getParent().args
			for k, v in pairs(frame.args) do
				origArgs = frame.args
				break
			end
		else
			origArgs = frame
		end
		-- Trim whitespace and remove blank arguments.
		local args = {}
		for k, v in pairs(origArgs) do
			if type(v) == 'string' then
				v = mw.text.trim(v)
			end
			if v ~= '' then
				args[k] = v
			end
		end
		return p.main(protectionType, args)
	end
end
 
local funcNames = {'semi', 'template', 'full'}
for _, funcName in ipairs(funcNames) do
	p[funcName] = makeWrapper(funcName)
end

return p