Module:Message box: Difference between revisions

Jump to navigation Jump to search
more abstraction for box structure and better small=yes support
(start work on a module for displaying Template:Mbox-family message boxes)
 
(more abstraction for box structure and better small=yes support)
Line 4:
 
local p = {}
 
local function generateBoxStructure()
local root = htmlBuilder.create() -- The template root. Includes error messages and categories added after the box.
local box = root.tag('table') -- The box.
local row = box.tag('tr')
return root, box, row
end
 
function p.build(data, args)
-- Process config data using the args passed to the template.
local isSmall = args.small == 'yes' or args.small == true
local typeData = data.types[args.type]
local invalidType = args.type and not typeData and true or false
typeData = typeData or data.types[data.default]
 
local image, imageRight, text, imageSize
if isSmall then
image = args.smallimage or args.image
imageRight = args.smallimageright or args.imageright
text = args.smalltext or args.text
imageSize = data.imageSizeSmall or data.imageSize
else
image = typeDataargs.image,
imageRight = args.imageright
text = ))args.text
imageSize = data.imageSizeLarge or data.imageSize
end
 
-- Get the box structure.
local root, box, row = generateBoxStructure()
 
-- Build the box.
local root = htmlBuilder.create() -- The template root. Includes error messages and categories added after the box.
local box = root.tag('table') -- The box.
box
.attr('id', args.id)
Line 28 ⟶ 49:
 
-- Add the left-hand image.
localif rowimage ~= box.tag('trnone') then
if args.image ~= 'none' then
row.tag('td')
.addClass('mbox-image')
.wikitext(args.image or mw.ustring.format('[[File:%s|%s|link=|alt=]]', typeData.image, imageSize))
'[[File:%s|%s|link=|alt=]]',
typeData.image,
(args.small == 'yes' or args.small == true) and data.imageSizeSmall or data.imageSizeLarge or data.imageSize
))
elseif data.imageEmptyCell then
row.tag('td')
Line 46 ⟶ 62:
.addClass('mbox-text')
.cssText(args.textstyle)
.wikitext(args.text)
 
-- Add the right-hand image.
if args.imagerightimageRight then
row.tag('td')
.addClass('mbox-imageright')
.wikitext(args.imagerightimageRight)
end
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu