« Module:Bases » : différence entre les versions
Contenu supprimé Contenu ajouté
Condition de non-nullité du texte des ucfirst etc. |
catégorie : troisième paramètre: true = affiche la catégorie avec :Catégorie |
||
Ligne 45 : | Ligne 45 : | ||
-- Renvoie une catégorie bien formée |
-- Renvoie une catégorie bien formée |
||
function b.fait_categorie(texte, clef) |
function b.fait_categorie(texte, clef, ecrite) |
||
local cat = ecrite and ':Catégorie:' or 'Catégorie:' |
|||
if (texte ~= nil) then |
if (texte ~= nil) then |
||
if (clef) then |
if (clef ~= nil and clef ~= '') then |
||
return '[[ |
return '[[' .. cat .. texte .. '|' .. clef .. ']]' |
||
else |
else |
||
return '[[ |
return '[[' .. cat .. texte .. ']]' |
||
end |
end |
||
else |
else |
Version du 28 mars 2013 à 00:39
La documentation pour ce module peut être créée à Module:Bases/Documentation
local b = {}
-- Doit-on faire une élision devant ce mot ?
function b.is_elidable(mot)
if (mw.ustring.match( mot, "^[aàâäeéèêëiîïoôöuùûü]" ) ~= nil) then
return true
else
return false
end
end
-- S'agit-il d'une locution ?
function b.is_locution(mot)
if (mw.ustring.find(mot, ' ') ~= nil) then
return true
else
return false
end
end
-- Renvoie le texte avec la première lettre en majuscule (si le texte est en français)
function b.ucfirst(texte)
if (texte == nil) then return texte end
locale = mw.language.new('fr')
return locale:ucfirst(texte)
end
-- Renvoie le texte avec la première lettre en minuscule (si le texte est en français)
function b.lcfirst(texte)
if (texte == nil) then return texte end
locale = mw.language.new('fr')
return locale:lcfirst(texte)
end
-- Renvoie le texte en majuscule (si le texte est en français)
function b.uc(texte)
if (texte == nil) then return texte end
locale = mw.language.new('fr')
return locale:uc(texte)
end
-- Renvoie le texte en minuscule (si le texte est en français)
function b.lc(texte)
if (texte == nil) then return texte end
locale = mw.language.new('fr')
return locale:lc(texte)
end
-- Renvoie une catégorie bien formée
function b.fait_categorie(texte, clef, ecrite)
local cat = ecrite and ':Catégorie:' or 'Catégorie:'
if (texte ~= nil) then
if (clef ~= nil and clef ~= '') then
return '[[' .. cat .. texte .. '|' .. clef .. ']]'
else
return '[[' .. cat .. texte .. ']]'
end
else
return ''
end
end
-- Crée l'entête d'un tableau wiki triable (avec les titres en paramètre)
function b.tableau_entete(titres)
local entete = '{| class="wikitable sortable"\r\n'
entete = entete .. '|-\r\n!' .. table.concat(titres, ' !! ')
return entete
end
-- Crée une ligne du tableau wiki
function b.tableau_ligne(elements)
local ligne = '|-\r\n|' .. table.concat(elements, ' || ')
return ligne
end
-- Crée la fin d'un tableau
function b.tableau_fin()
return "|}\r\n"
end
return b