« Module:Notice » : différence entre les versions
fr>Fxfxfx0 Aucun résumé des modifications |
fr>Fxfxfx0 Mise à jour du contenu ou de la documentation du modèle |
||
Ligne 1 : | Ligne 1 : | ||
local p = {} | local p = {} | ||
function p. | -- Function to format usernames | ||
function p.formatUsernames(usernames) | |||
local formattedUsers = {} | |||
for user in string.gmatch(usernames, '([^,]+)') do | |||
user = user:gsub("^%s*(.-)%s*$", "%1") -- Trim whitespace | |||
table.insert(formattedUsers, string.format('[[Utilisateur:%s|%s]]', user, user)) | |||
end | |||
return table.concat(formattedUsers, ', ') | |||
return | |||
end | end | ||
Ligne 20 : | Ligne 14 : | ||
function p.main(frame) | function p.main(frame) | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
local usernames = args.users or '' | |||
local formattedUsernames = p.formatUsernames(usernames) | |||
local color = args.color or 'green' | local color = args.color or 'green' | ||
local align = args.align or '' | local align = args.align or '' | ||
Ligne 28 : | Ligne 25 : | ||
local header = args.header or '' | local header = args.header or '' | ||
local content = args.content or '' | local content = args.content or '' | ||
-- Existing code for creating the notice... | |||
local root = mw.html.create('div') | local root = mw.html.create('div') | ||
Ligne 34 : | Ligne 33 : | ||
:css('text-align', textAlign) | :css('text-align', textAlign) | ||
:css('border-color', p.getStyleForColor(color)) | :css('border-color', p.getStyleForColor(color)) | ||
:css('border-radius', " | :css('border-radius', "5px") | ||
:css('border-style', "solid") | :css('border-style', "solid") | ||
:css('border-width', "1px 5px | :css('border-width', "1px 5px") | ||
:css('margin', ".5em 0") | :css('margin', ".5em 0") | ||
:css('padding', ".5em") | :css('padding', ".5em") | ||
-- Add the formatted usernames to the content | |||
local userMessage = formattedUsernames .. " signale(nt) qu’il(s) travaille(nt) actuellement sur cette page!" | |||
local contentDiv = root:tag('div') | local contentDiv = root:tag('div') | ||
:addClass('notice-content') | |||
:css('flex-grow', 1) | |||
if header ~= '' then | if header ~= '' then | ||
Ligne 68 : | Ligne 53 : | ||
contentDiv:tag('div') | contentDiv:tag('div') | ||
:addClass('notice-description') | |||
:css('font-size', "9pt") | |||
:wikitext(userMessage .. "<br /><small>Vous pouvez ajouter votre nom en modifiant ce modèle. Vous pouvez supprimer ce modèle si la personne n’a pas édité depuis plusieurs mois.</small>") | |||
return tostring(root) | return tostring(root) |
Version du 17 juillet 2024 à 00:18
Usage
Use this template to create other Notice Templates.
Syntax: {{notice|align=|text-align=|width=|file=|filesize=|header=|content=}}
color
|
Named, optional | The color preset for the border. Defined options are green , blue , teal , orange , yellow , red , maroon , pink , and gray . However, if a color is a known CSS color, it can be used. Defaults to green .
| |||
text-align
|
Named, optional | The text-align attribute of the header and content text, e.g. center . Defaults to left .
| |||
file
|
Named, optional | The file to show on the left-hand section as a filename. e.g. Example.jpg . Defaults to nothing shown.
| |||
filesize
|
Named, optional | The file's size on the left-hand section. e.g. 30px . Defaults to 48px if a file was specified, otherwise none.
| |||
header
|
Named, optional | The header text. e.g. Notice . Defaults to nothing shown.
| |||
content
|
Named, optional | The content text. e.g. Test message . Defaults to nothing shown.
| |||
width
|
Named, optional | The width attribute of the notice, e.g. 30% . Defaults to unwritten (inherit).
|
Examples
{{notice|file=Example.jpg|header=Under Construction|content=This article is under construction.}}
Erreur Lua à la ligne 34 : attempt to call field 'getStyleForColor' (a nil value).
{{notice|file=Example.jpg|header=Notice with header text only.}}
Erreur Lua à la ligne 34 : attempt to call field 'getStyleForColor' (a nil value).
{{notice|file=Example.jpg|content=Small notice without a header.}}
Erreur Lua à la ligne 34 : attempt to call field 'getStyleForColor' (a nil value).
{{notice|file=Example.jpg|header=Green notice|color=green}}
Erreur Lua à la ligne 34 : attempt to call field 'getStyleForColor' (a nil value).
{{notice|file=Example.jpg|header=Blue notice with custom width|width=30%|color=blue}}
Erreur Lua à la ligne 34 : attempt to call field 'getStyleForColor' (a nil value).
{{notice|file=Example.jpg|header=Teal notice|color=teal}}
Erreur Lua à la ligne 34 : attempt to call field 'getStyleForColor' (a nil value).
{{notice|file=Example.jpg|header=Orange notice|color=orange}}
Erreur Lua à la ligne 34 : attempt to call field 'getStyleForColor' (a nil value).
{{notice|file=Example.jpg|header=Yellow notice|color=yellow}}
Erreur Lua à la ligne 34 : attempt to call field 'getStyleForColor' (a nil value).
{{notice|file=Example.jpg|header=Red notice|color=red}}
Erreur Lua à la ligne 34 : attempt to call field 'getStyleForColor' (a nil value).
{{notice|file=Example.jpg|header=Maroon notice|color=maroon}}
Erreur Lua à la ligne 34 : attempt to call field 'getStyleForColor' (a nil value).
{{notice|file=Example.jpg|header=Pink notice|color=pink}}
Erreur Lua à la ligne 34 : attempt to call field 'getStyleForColor' (a nil value).
{{notice|file=Example.jpg|header=Gray notice|color=gray}}
Erreur Lua à la ligne 34 : attempt to call field 'getStyleForColor' (a nil value).
{{notice|file=Example.jpg|header=Custom color notice|color=slateblue|text-align=center}}
Erreur Lua à la ligne 34 : attempt to call field 'getStyleForColor' (a nil value).
local p = {}
-- Function to format usernames
function p.formatUsernames(usernames)
local formattedUsers = {}
for user in string.gmatch(usernames, '([^,]+)') do
user = user:gsub("^%s*(.-)%s*$", "%1") -- Trim whitespace
table.insert(formattedUsers, string.format('[[Utilisateur:%s|%s]]', user, user))
end
return table.concat(formattedUsers, ', ')
end
-- Entry point for the module
function p.main(frame)
local args = frame:getParent().args
local usernames = args.users or ''
local formattedUsernames = p.formatUsernames(usernames)
local color = args.color or 'green'
local align = args.align or ''
local textAlign = args['text-align'] or 'left'
local width = args.width or ''
local file = args.file or ''
local fileSize = args.filesize or '48px'
local header = args.header or ''
local content = args.content or ''
-- Existing code for creating the notice...
local root = mw.html.create('div')
:addClass('notice')
:attr('align', align)
:css('text-align', textAlign)
:css('border-color', p.getStyleForColor(color))
:css('border-radius', "5px")
:css('border-style', "solid")
:css('border-width', "1px 5px")
:css('margin', ".5em 0")
:css('padding', ".5em")
-- Add the formatted usernames to the content
local userMessage = formattedUsernames .. " signale(nt) qu’il(s) travaille(nt) actuellement sur cette page!"
local contentDiv = root:tag('div')
:addClass('notice-content')
:css('flex-grow', 1)
if header ~= '' then
contentDiv:tag('div')
:addClass('notice-header')
:css('font-weight', 600)
:wikitext(header)
end
contentDiv:tag('div')
:addClass('notice-description')
:css('font-size', "9pt")
:wikitext(userMessage .. "<br /><small>Vous pouvez ajouter votre nom en modifiant ce modèle. Vous pouvez supprimer ce modèle si la personne n’a pas édité depuis plusieurs mois.</small>")
return tostring(root)
end
return p