« Module:CGTBox » : différence entre les versions

De USAC-CGT
Aller à la navigation Aller à la recherche
Aucun résumé des modifications
Aucun résumé des modifications
Ligne 1 : Ligne 1 :
local p = {} --p stands for package
local p = {} --p stands for package
local title = mw.title.getCurrentTitle().text
local contents = {} -- table for html element for the contents of the box


--
--
Ligne 9 : Ligne 6 :
local function addTitle(title)
local function addTitle(title)
return mw.html.create('div')
return mw.html.create('div')
:addClass('entete')
:addClass('titre')
:node(mw.html.create('div'):wikitext(title):done())
:wikitext(title)
:allDone()
:done()
end
end


--
--
-- Génère la boite à partir du titre (title) et de la table contents
-- Génère la boite à partir du titre (title) et de la table contents (contient une suite d'élément html)
--
--
local function returnBox(t, c)
local function returnBox(title, contents)
--box
--box
local box = mw.html.create('div')
local box = mw.html.create('div')
  :addClass('infobox_v3')
  :addClass('CGTBox')
--Title
--Title
box:node(addTitle(t))
box:node(addTitle(title))


--contents
--contents
for i, v in ipairs(c) do
for i, v in ipairs(contents) do
box:node(v)
box:node(v)
end
end
Ligne 35 : Ligne 32 :
end    
end    


function p.hello( frame )
--
-- Créer une box générique (un titre (title) et du contenu (contents))
--
function p.boxGeneric( frame )
local params = frame:getParent().args or frame.args
-- Titre
local title = params.title or 'Titre'
local contents = {} -- table for html element for the contents of the box
 
contents[#contents + 1] = mw.html.create('span')
contents[#contents + 1] = mw.html.create('span')
  :wikitext("Hello, world 2!")
  :wikitext(params.contents or 'Contenu')
  :done()
  :done()



Version du 23 septembre 2023 à 09:57

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

local p = {} --p stands for package

--
-- Retourne le titre sous forme html
--
local function addTitle(title)
	return mw.html.create('div')
		:addClass('titre')
		:wikitext(title)
		:done()
end

--
-- Génère la boite à partir du titre (title) et de la table contents (contient une suite d'élément html)
--
local function returnBox(title, contents)
	--box
	local box = mw.html.create('div')
	  :addClass('CGTBox')
	
	--Title
	box:node(addTitle(title))

	--contents
	for i, v in ipairs(contents) do
		box:node(v)
	end
	
	box:done()
	
	return box
end	  

--
-- Créer une box générique (un titre (title) et du contenu (contents))
--
function p.boxGeneric( frame )
	local params = frame:getParent().args or frame.args
	
	-- Titre
	local title = params.title or 'Titre'
	local contents = {} -- table for html element for the contents of the box

	contents[#contents + 1] = mw.html.create('span')
	  :wikitext(params.contents or 'Contenu')
	  :done()

	
    return returnBox(title, contents)
end

return p