require('strict')local p = local data = mw.loadData('Module:Badge display/data')local getArgs = require('Module:Arguments').getArgslocal GlobalTemplateArgs = -- define as global (to this module) variable
function p.DisplayImage(frame) -- Usage from a template etc: --
local args = getArgs(frame)
-- Set default values for optional parameters local float = args.float or 'none' if float
"right" then float = "floatright" end end if float
code then -- return '
Error: missing positional parameter 1' return ' (Invalid Code: ' .. code .. ') ' end -- local code = code:upper -- DO NOT DO THIS. Code is case sensitive -- Converts the first argument to uppercase if not data[code] then -- return 'Error: invalid positional parameter 1: ' .. code .. '' return ' (Code not found: ' .. code .. ') ' end-- -- Data from the record into local variables local Code = data[code].Code local Type = data[code].Type local Description = data[code].Description local Class = data[code].Class local Variation = data[code].Variation local Image = data[code].Image local PageLink = data[code].PageLink local Country = data[code].Country local Note = data[code].Note local Org = data[code].Org local caption = if string.len(Image) < 1 then Image="Ribbon - Question mark.png" end local NoTable = args.NoTable or if string.len(NoTable) > 0 then -- Do not output a table, just the badge local output = output = output .. "" return output -- This will exit the function and stop processing further end
local DescOnly = args.DescOnly or if string.len(DescOnly) > 0 then -- Do not output a table, just the badge with a description if DescOnly ~= "yes" then -- Hidden option to over-ride the description Description=DescOnly end local output = output = output .. "" output = output .. " " .. Description .. "" return output -- This will exit the function and stop processing further end
-- Build the wikitext table local wikitext= wikitext = wikitext .. '
-\n' wikitext = wikitext .. ' | \n | -\n' wikitext = wikitext .. ' | ' -- .. Description if string.len(Class) > 1 then wikitext = wikitext .. Class .. " " end if string.len(Variation) > 1 then wikitext = wikitext .. Variation .. " " end if string.len(Note) > 1 then wikitext = wikitext .. "" .. Note .. "" end wikitext = wikitext .. '\n | -\n' wikitext = wikitext .. ' |
-\n" -- xx =, tableCode = tableCode .. "! Code | Type | Description | Class | Variation | Image | Note | Country\n" -- Iterate through the data in the table "GunnerData" for code, record in pairs(data) do -- Generate wiki table code for the Badges tableCode = tableCode .. " | -\n" tableCode = tableCode .. " | " ..code .. "\n" -- tableCode = tableCode .. " | " .. record.Code .. "\n" tableCode = tableCode .. " | " .. record.Type .. "\n" if string.len(record.PageLink) < 1 then tableCode = tableCode .. " | " .. record.Description else tableCode = tableCode .. " | " .. "" .. record.Description .. "" end tableCode = tableCode .. "\n" tableCode = tableCode .. " | " .. record.Class .. "\n" tableCode = tableCode .. " | " .. record.Variation .. "\n" tableCode = tableCode .. " | \n" tableCode = tableCode .. ' | style=\"text-align: left;\" | ' .. record.Note .. "\n" tableCode = tableCode .. " | " .. record.Country .. "\n" end tableCode = tableCode .. " |
---|
return p-- Initial Code by John Dovey (19 April 2023)