Jump to content

Module:Badge display

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by BoonDock (talk | contribs) at 20:58, 18 April 2023 (Create the Module). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

local p = {}
local getArgs = require('Module:Arguments').getArgs
local args = getArgs(frame)
    
function p.DisplayImage(frame)
	-- Usage from a template etc:
--	{{#invoke:ModuleName|main
--| image = NameOfImage.jpg
--| caption = Caption for the image
--| description = Description of the image
--| float = left/right/center
--| height = height in pixels or other units
--| width = width in pixels or other units
--| size = size in pixels or other units, e.g. "x25px"
--}}
    -- Set default values for optional parameters
    local float = args.float or 'none'
    local height = args.height or ''
    local width = args.width or ''
    local size = args.size or ''

    -- Build the HTML table
    local html = mw.html.create('table')
    html
        :css('float', float)
        :wikitext([[
            <tr>
                <td>]] .. (args.caption or '') .. [[</td>
            </tr>
            <tr>
                <td><div style="text-align:center;">]] .. (args.image or '') .. [[</div></td>
            </tr>
            <tr>
                <td>]] .. (args.description or '') .. [[</td>
            </tr>
        ]])
    if height ~= '' or width ~= '' or size ~= '' then
        local style = ''
        if height ~= '' then
            style = style .. 'height:' .. height .. ';'
        end
        if width ~= '' then
            style = style .. 'width:' .. width .. ';'
        end
        if size ~= '' then
            style = style .. 'height:' .. size .. ';width:' .. size .. ';'
        end
        html:css('max-width', '100%'):cssText(style)
    end
    return tostring(html)
end

return p