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 22:38, 18 April 2023 (Test // Edit via Wikitext Extension for VSCode). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}
local getArgs = require('Module:Arguments').getArgs


function p.DisplayImage(frame)
    -- Usage from a template etc:
    -- {{#invoke:BadgeDisplay|DisplayImage
    -- | image = NameOfImage.jpg
    -- | caption = Caption for the image
    -- | description = Description of the image
    -- | float = left/right/center
    -- | width = width in pixels or other units of the table
    -- | size = size in pixels or other units, e.g. "x25px"
    -- }}

    local args = getArgs(frame)

    -- Set default values for optional parameters
    local float = args.float or 'none'
    local size = args.size or '200'
	local imageName = args.image or ''
    local width = args.width or ''

    -- Build the wikitext table
    local wikitext=''
    -- if width then 
    --    wikitext = wikitext .. '{| class="wikitable" style="width:' .. (tonumber(width) * 1.1) .. 'px; margin:0 auto;border:none;"\n'
    -- else
        wikitext = wikitext .. '{| class="wikitable" style="width:250px; margin:0 auto;border:none;"\n'
    -- end

    wikitext = wikitext .. '|caption style="text-align:center;"|' .. (args.caption or 'No Caption') .. '\n|-\n'
    wikitext = wikitext .. '|style="text-align:center;border:none;"| [[File:' .. (args.image or 'No Image') .. '|' .. size .. ']]\n|-\n'
    --wikitext = wikitext .. '|style="text-align:center;"| [[File:' .. (args.image or 'No Image') .. ']]\n|-\n'
    wikitext = wikitext .. '|style="text-align:center;"|' .. (args.description or 'No Description') .. '\n|-\n'
    wikitext = wikitext .. '|}\n'
    wikitext = wikitext .. '=== Debug === \n'
    wikitext = wikitext .. '* float: ' .. float .. '\n'
    wikitext = wikitext .. '* width: ' .. width .. '\n'
    wikitext = wikitext .. '* size: ' .. size .. '\n'
    wikitext = wikitext .. '* imageName: ' .. imageName .. '\n'

    return wikitext
end

return p