« Module:Pistes » : différence entre les versions
mAucun résumé des modifications |
Déplacement des styles dans TemplateStyles |
||
Ligne 29 : | Ligne 29 : | ||
-- 2. Initialisation du tableau de la liste des titres |
-- 2. Initialisation du tableau de la liste des titres |
||
local divPistes = mw.html.create( 'div' ) |
local divPistes = mw.html.create( 'div' ) |
||
:addClass( "overflow" ) |
:addClass( "overflow pistes-marge" ) |
||
:css({ |
:css({ |
||
⚫ | |||
margin = '0 auto', |
|||
['padding-left'] = '1px', |
|||
⚫ | |||
overflow = 'hidden' |
|||
}) |
}) |
||
local tabPistes = divPistes |
local tabPistes = divPistes |
||
Ligne 40 : | Ligne 37 : | ||
:addClass( "tracklist" .. (args.collapsed == 'oui' and " collapsible collapsed" or "" )) |
:addClass( "tracklist" .. (args.collapsed == 'oui' and " collapsible collapsed" or "" )) |
||
:attr( 'cellpadding', "0" ) |
:attr( 'cellpadding', "0" ) |
||
:css({ |
|||
width = '100%', |
|||
['border-width'] = '0px', |
|||
['border-collapse'] = 'collapse' |
|||
}) |
|||
-- 3. Éventuel code avant l'entête du tableau (titre ou boîte repliable) |
-- 3. Éventuel code avant l'entête du tableau (titre ou boîte repliable) |
||
Ligne 51 : | Ligne 43 : | ||
:tag( "tr" ) |
:tag( "tr" ) |
||
:tag( "th" ) |
:tag( "th" ) |
||
:addClass( "tlheader" ) |
:addClass( "tlheader pistes-titre" ) |
||
:attr( "scope", "col" ) |
:attr( "scope", "col" ) |
||
:attr( "colspan", "10" ) |
:attr( "colspan", "10" ) |
||
:css({ |
|||
['text-align'] = 'left', |
|||
['background-color'] = 'var(--background-color-base, #fff)', |
|||
color = 'var(--color-base, #202122)', |
|||
['border-width'] = '0' |
|||
}) |
|||
:wikitext( (args["langue titre"] or args["langue titres"]) and langue.langue({ args["langue titre"] or args["langue titres"], args.titre or args.headline }) or (args.titre or args.headline) ) |
:wikitext( (args["langue titre"] or args["langue titres"]) and langue.langue({ args["langue titre"] or args["langue titres"], args.titre or args.headline }) or (args.titre or args.headline) ) |
||
elseif args.collapsed == 'oui' then |
elseif args.collapsed == 'oui' then |
||
Ligne 65 : | Ligne 51 : | ||
:tag( "tr" ) |
:tag( "tr" ) |
||
:tag( "th" ) |
:tag( "th" ) |
||
:addClass( "tlheader" ) |
:addClass( "tlheader pistes-titre" ) |
||
:attr( "colspan", "10" ) |
:attr( "colspan", "10" ) |
||
:css({ |
|||
['text-align'] = 'left', |
|||
['background-color'] = 'var(--background-color-base, #fff)', |
|||
color = 'var(--color-base, #202122)', |
|||
['border-width'] = '0' |
|||
}) |
|||
:wikitext( " " ) |
:wikitext( " " ) |
||
end |
end |
||
Ligne 83 : | Ligne 63 : | ||
:tag( "tr" ) |
:tag( "tr" ) |
||
:tag( "th" ) -- Colonne « Numéro » |
:tag( "th" ) -- Colonne « Numéro » |
||
:addClass( "tlheader" ) |
:addClass( "tlheader pistes-entete" ) |
||
:attr( "scope", "col" ) |
:attr( "scope", "col" ) |
||
:css({ |
:css({ |
||
Ligne 89 : | Ligne 69 : | ||
['padding-left'] = '10px', |
['padding-left'] = '10px', |
||
['padding-right'] = '10px', |
['padding-right'] = '10px', |
||
['text-align'] = 'right' |
['text-align'] = 'right' |
||
['background-color'] = 'var(--background-color-neutral, #eaecf0)', |
|||
color = 'var(--color-base, #202122)' |
|||
}) |
}) |
||
:wikitext( mw.getCurrentFrame():expandTemplate({ title = 'Numéro avec majuscule', args = { espace = 'non' }}) ) |
:wikitext( mw.getCurrentFrame():expandTemplate({ title = 'Numéro avec majuscule', args = { espace = 'non' }}) ) |
||
:done() |
:done() |
||
:tag( "th" ) -- Colonne « Titre » |
:tag( "th" ) -- Colonne « Titre » |
||
:addClass( "tlheader" ) |
:addClass( "tlheader pistes-entete" ) |
||
:attr( "scope", "col" ) |
:attr( "scope", "col" ) |
||
:css({ |
:css({ |
||
width = ({[0]='100%', [1]='60%', [2]='40%', [3]='30%', [4]='20%'})[nbColonnesExtra] |
width = ({[0]='100%', [1]='60%', [2]='40%', [3]='30%', [4]='20%'})[nbColonnesExtra] |
||
['text-align'] = 'left', |
|||
['background-color'] = 'var(--background-color-neutral, #eaecf0)', |
|||
color = 'var(--color-base, #202122)' |
|||
}) |
}) |
||
:wikitext( "Titre" ) |
:wikitext( "Titre" ) |
||
Ligne 109 : | Ligne 84 : | ||
entetesPistes |
entetesPistes |
||
:tag( "th" ) |
:tag( "th" ) |
||
:addClass( "pistes-entete" ) |
|||
:attr( "scope", "col" ) |
:attr( "scope", "col" ) |
||
:css({ |
:css({ |
||
width = ({[1]='40%', [2]='30%', [3]='20%', [4]='20%'})[nbColonnesExtra] |
width = ({[1]='40%', [2]='30%', [3]='20%', [4]='20%'})[nbColonnesExtra] |
||
['text-align'] = 'left', |
|||
['background-color'] = 'var(--background-color-neutral, #eaecf0)', |
|||
color = 'var(--color-base, #202122)' |
|||
}) |
}) |
||
:wikitext( "Paroles" ) |
:wikitext( "Paroles" ) |
||
Ligne 122 : | Ligne 95 : | ||
entetesPistes |
entetesPistes |
||
:tag( "th" ) |
:tag( "th" ) |
||
:addClass( "pistes-entete" ) |
|||
:attr( "scope", "col" ) |
:attr( "scope", "col" ) |
||
:css({ |
:css({ |
||
width = ({[1]='40%', [2]='30%', [3]='20%', [4]='20%'})[nbColonnesExtra] |
width = ({[1]='40%', [2]='30%', [3]='20%', [4]='20%'})[nbColonnesExtra] |
||
['text-align'] = 'left', |
|||
['background-color'] = 'var(--background-color-neutral, #eaecf0)', |
|||
color = 'var(--color-base, #202122)' |
|||
}) |
}) |
||
:wikitext( "Musique" ) |
:wikitext( "Musique" ) |
||
Ligne 135 : | Ligne 106 : | ||
entetesPistes |
entetesPistes |
||
:tag( "th" ) |
:tag( "th" ) |
||
:addClass( "pistes-entete" ) |
|||
:attr( "scope", "col" ) |
:attr( "scope", "col" ) |
||
:css({ |
:css({ |
||
width = ({[1]='40%', [2]='30%', [3]='20%', [4]='20%'})[nbColonnesExtra] |
width = ({[1]='40%', [2]='30%', [3]='20%', [4]='20%'})[nbColonnesExtra] |
||
['text-align'] = 'left', |
|||
['background-color'] = 'var(--background-color-neutral, #eaecf0)', |
|||
color = 'var(--color-base, #202122)' |
|||
}) |
}) |
||
:wikitext( "Auteur" ) |
:wikitext( "Auteur" ) |
||
Ligne 148 : | Ligne 117 : | ||
entetesPistes |
entetesPistes |
||
:tag( "th" ) |
:tag( "th" ) |
||
:addClass( "pistes-entete" ) |
|||
:attr( "scope", "col" ) |
:attr( "scope", "col" ) |
||
:css({ |
:css({ |
||
width = ({[1]='40%', [2]='30%', [3]='20%', [4]='20%'})[nbColonnesExtra] |
width = ({[1]='40%', [2]='30%', [3]='20%', [4]='20%'})[nbColonnesExtra] |
||
['text-align'] = 'left', |
|||
['background-color'] = 'var(--background-color-neutral, #eaecf0)', |
|||
color = 'var(--color-base, #202122)' |
|||
}) |
}) |
||
:wikitext( args.colonne_extra or args.extra_column ) |
:wikitext( args.colonne_extra or args.extra_column ) |
||
Ligne 160 : | Ligne 127 : | ||
entetesPistes |
entetesPistes |
||
:tag( "th" ) -- Colonne « Durée » |
:tag( "th" ) -- Colonne « Durée » |
||
:addClass( "tlheader" ) |
:addClass( "tlheader pistes-entete" ) |
||
:attr( "scope", "col" ) |
:attr( "scope", "col" ) |
||
:css({ |
:css({ |
||
Ligne 184 : | Ligne 151 : | ||
ligne |
ligne |
||
:tag( 'th' ) |
:tag( 'th' ) |
||
:addClass( "pistes-numero" ) |
|||
:attr{ scope = 'row' } |
:attr{ scope = 'row' } |
||
:css({ |
|||
['padding-right'] = '10px', |
|||
['text-align'] = 'right', |
|||
['font-weight'] = 'normal' |
|||
}) |
|||
:wikitext( (args[i].numero or tostring(i)) .. '.' ) |
:wikitext( (args[i].numero or tostring(i)) .. '.' ) |
||
local titre |
local titre |
||
Ligne 223 : | Ligne 185 : | ||
end |
end |
||
ligne:tag('td') |
ligne:tag('td') |
||
: |
:addClass( 'pistes-duree' ) |
||
['padding-right'] = '10px', |
|||
['text-align'] = 'right' |
|||
}) |
|||
:wikitext( args[i].temps or args[i].length ) |
:wikitext( args[i].temps or args[i].length ) |
||
end |
end |
Version du 17 mai 2024 à 22:01
Utilisation
Ce module est conçu pour une utilisation à travers le modèle Modèle:Pistes. Il fournit une fonction permettant la génération du tableau correspondant à une liste de pistes audio, avec indication du titre et de la durée et d'autres paramètres optionnels.
Le style du modèle est géré par Modèle:Pistes/styles.css.
Fonctions exportables
main(frame)
– Prend en argument un frame et retourne une chaîne de caractères contenant le code html d'un tableau.
Modules externes et autres éléments dont ce module a besoin pour fonctionner
mw.ustring.match
– Cherche la première correspondance d'un motif dans une chaine de caractères ;mw.text.trim
– Enlève les espaces au début et à la fin d'une chaine de caractères ;mw.html.create
– Crée un nouvel objet mw.html, équivalent d'un élément HTML ;
Module:Langue
– Module de mise en forme du contenu en langue étrangère.
Modules lua utilisant ce module
Aucun
Modèles appelant directement ce module
Exemples
Dans Modèle:Pistes, ce module est appelé par le code suivant :
{{#invoke:Pistes|main}}
La documentation de ce module est générée par le modèle {{Documentation module}}.
Elle est incluse depuis sa sous-page de documentation. Veuillez placer les catégories sur cette page-là.
Les éditeurs peuvent travailler dans le bac à sable (modifier).
Voir les statistiques d'appel depuis le wikicode sur l'outil wstat et les appels depuis d'autres modules.
local p = {}
local langue = require 'Module:Langue'
local nbPistes = 0
function p.main( frame )
-- 1. Lecture des paramètres
local args = {}
for k, v in pairs(frame:getParent().args) do
local param, nb = mw.ustring.match( k, '(.+)(%d+)' )
if nb then
nb = tonumber(nb)
if nb and args[nb] == nil then
if nb > nbPistes then
nbPistes = nb
end
args[nb] = {}
end
args[nb][param] = mw.text.trim(v)
args[nb][param] = args[nb][param] ~= "" and args[nb][param] or nil
else
args[k] = mw.text.trim(v)
args[k] = args[k] ~= "" and args[k] or nil
end
end
-- 2. Initialisation du tableau de la liste des titres
local divPistes = mw.html.create( 'div' )
:addClass( "overflow pistes-marge" )
:css({
['margin-bottom'] = args.total_temps and args.total_temps ~= '' and '0.5em' or '1em'
})
local tabPistes = divPistes
:tag( "table" )
:addClass( "tracklist" .. (args.collapsed == 'oui' and " collapsible collapsed" or "" ))
:attr( 'cellpadding', "0" )
-- 3. Éventuel code avant l'entête du tableau (titre ou boîte repliable)
if args.titre or args.headline then
tabPistes
:tag( "tr" )
:tag( "th" )
:addClass( "tlheader pistes-titre" )
:attr( "scope", "col" )
:attr( "colspan", "10" )
:wikitext( (args["langue titre"] or args["langue titres"]) and langue.langue({ args["langue titre"] or args["langue titres"], args.titre or args.headline }) or (args.titre or args.headline) )
elseif args.collapsed == 'oui' then
tabPistes
:tag( "tr" )
:tag( "th" )
:addClass( "tlheader pistes-titre" )
:attr( "colspan", "10" )
:wikitext( " " )
end
-- 4. Création de l'entête du tableau
local nbColonnesExtra = ((args.credits_paroles or args.lyrics_credits) and 1 or 0) + ((args.credits_musique or args.music_credits) and 1 or 0) + ((args.credits_ecriture or args.writing_credits) and 1 or 0) + ((args.colonne_extra or args.extra_column) and 1 or 0)
local entetesPistes = tabPistes
:tag( "tr" )
:tag( "th" ) -- Colonne « Numéro »
:addClass( "tlheader pistes-entete" )
:attr( "scope", "col" )
:css({
width = '20px',
['padding-left'] = '10px',
['padding-right'] = '10px',
['text-align'] = 'right'
})
:wikitext( mw.getCurrentFrame():expandTemplate({ title = 'Numéro avec majuscule', args = { espace = 'non' }}) )
:done()
:tag( "th" ) -- Colonne « Titre »
:addClass( "tlheader pistes-entete" )
:attr( "scope", "col" )
:css({
width = ({[0]='100%', [1]='60%', [2]='40%', [3]='30%', [4]='20%'})[nbColonnesExtra]
})
:wikitext( "Titre" )
:done()
if args.credits_paroles == 'oui' or args.lyrics_credits == 'oui' then -- Colonne « Paroles »
entetesPistes
:tag( "th" )
:addClass( "pistes-entete" )
:attr( "scope", "col" )
:css({
width = ({[1]='40%', [2]='30%', [3]='20%', [4]='20%'})[nbColonnesExtra]
})
:wikitext( "Paroles" )
:done()
end
if args.credits_musique == 'oui' or args.music_credits == 'oui' then -- Colonne « Musique »
entetesPistes
:tag( "th" )
:addClass( "pistes-entete" )
:attr( "scope", "col" )
:css({
width = ({[1]='40%', [2]='30%', [3]='20%', [4]='20%'})[nbColonnesExtra]
})
:wikitext( "Musique" )
:done()
end
if args.credits_ecriture == 'oui' or args.writing_credits == 'oui' then -- Colonne « Auteur »
entetesPistes
:tag( "th" )
:addClass( "pistes-entete" )
:attr( "scope", "col" )
:css({
width = ({[1]='40%', [2]='30%', [3]='20%', [4]='20%'})[nbColonnesExtra]
})
:wikitext( "Auteur" )
:done()
end
if args.colonne_extra or args.extra_column then -- Colonne extra
entetesPistes
:tag( "th" )
:addClass( "pistes-entete" )
:attr( "scope", "col" )
:css({
width = ({[1]='40%', [2]='30%', [3]='20%', [4]='20%'})[nbColonnesExtra]
})
:wikitext( args.colonne_extra or args.extra_column )
:done()
end
entetesPistes
:tag( "th" ) -- Colonne « Durée »
:addClass( "tlheader pistes-entete" )
:attr( "scope", "col" )
:css({
width = '60px',
['padding-right'] = '10px',
['text-align'] = 'right',
['background-color'] = 'var(--background-color-neutral, #eaecf0)',
color = 'var(--color-base, #202122)'
})
:wikitext( "Durée" )
:done()
-- 5. Tracé des lignes du tableau
for i = 1, nbPistes do
if args[i] and (args[i].piste or args[i].title or args[i].note or args[i].temps or args[i].length) then
local ligne = tabPistes:tag( 'tr' )
if i%2 == 0 then
ligne:css( 'background-color', 'var(--background-color-base, #fff)')
else
ligne:css( 'background-color', '#f7f7f7') --couleur pas adaptée selon mode sombre / pas sombre
end
ligne
:tag( 'th' )
:addClass( "pistes-numero" )
:attr{ scope = 'row' }
:wikitext( (args[i].numero or tostring(i)) .. '.' )
local titre
if args[i].piste or args[i].title then
local nonLatin = langue.nonLatin( args[i].piste or args[i].title )
if nonLatin then
titre = args[i].piste or args[i].title
else
titre = "''" .. (args[i].piste or args[i].title) .. "''"
end
if args[i].langue or args["langue titres"] then
titre = langue.langue({ args[i].langue or args["langue titres"], titre })
end
else
titre = 'Sans titre'
end
if args[i].note then
titre = titre .. ' <small>(' .. args[i].note .. ')</small>'
end
ligne:tag ( 'td' ):wikitext( titre )
if args.credits_paroles == 'oui' or args.lyrics_credits == 'oui' then
ligne:tag( 'td' ):wikitext( args[i].paroles or args[i].lyrics )
end
if args.credits_musique == 'oui' or args.music_credits == 'oui' then
ligne:tag( 'td' ):wikitext( args[i].musique or args[i].music )
end
if args.credits_ecriture == 'oui' or args.writing_credits == 'oui' then
ligne:tag( 'td' ):wikitext( args[i].auteur or args[i].writer )
end
if args.colonne_extra or args.extra_column then
ligne:tag( 'td' ):wikitext( args[i].extra )
end
ligne:tag('td')
:addClass( 'pistes-duree' )
:wikitext( args[i].temps or args[i].length )
end
end
if args.total_temps then
tabPistes:tag( 'tr' ):tag('td')
:attr( 'colspan', '10' )
:css({
['padding-right'] = '10px',
['text-align'] = 'right',
['background-color'] = 'var(--background-color-base, #fff)',
color = 'var(--color-base, #202122)',
['font-weight'] = 'bold',
['border-width'] = '0'
})
:wikitext( args.total_temps )
end
return tostring( divPistes )
end
return p