Module:Navbox

local p = {}

local utilsArg = require("Module:UtilsArg")

local DEFAULT_IMG_SIZE = "150x150px"

function p.Main(frame) local args, err = utilsArg.parse(frame:getParent.args, p.Templates.Navbox) local categories = err and err.categoryText or "" if not args.title then return "", categories end local navboxContent = mw.html.create("div") :addClass("navbox mw-collapsible mw-collapsed") :tag("div") :addClass("navbox__header mw-collapsible-toggle") :tag("span") -- Used to center the heading - see Template:Navbox/Styles.css :addClass("navbox__toggle-button-counterbalance") :done :tag("span") :addClass("navbox__title") :wikitext(args.title) :done :tag("span") :addClass("navbox__toggle-button") :tag("span") :addClass("navbox__toggle-button-text mw-collapsible-text") :done :done :done :done :tag("div") :addClass("navbox__content mw-collapsible-content") local body = navboxContent:tag("div") :addClass("navbox__body") local rows = body:tag("div") :addClass("navbox__rows") for i, row in ipairs(args.rows) do		local links = table.concat(row.links or "", " • ") local evenOdd = (i % 2 == 0) and "even" or "odd" if row.group then rows:tag("div") :wikitext(row.group) :addClass("navbox__row-header") :done :tag("div") :wikitext(links) :addClass("navbox__row-links navbox__row-links--"..evenOdd) :done end end if args.image then local filename = args.image if not string.find(filename, "^File:") then filename = "File:"..filename end local thumbnail = string.format("%s", filename, DEFAULT_IMG_SIZE) body:tag("div") :addClass("navbox__image") :wikitext(thumbnail) end if args.footer then navboxContent:tag("div") :addClass("navbox__footer") :wikitext(args.footer) end local result = tostring(navboxContent:allDone) return result, categories end

p.Templates = { ["Navbox"] = { format = "block", purpose = "Creates navbox templates", categories = {"Metatemplates"}, boilerplate = { separateRequiredParams = false, },		paramOrder = {"title", "image", "group", "links", "footer"}, repeatedGroup = { name = "rows", params = {"group", "links"}, counts = {2, 3, 4, 5, 6, 7}, },		params = { title = { required = true, type = "content", desc = "The navbox title.", trim = true, nilIfEmpty = true, },			image = { type = "wiki-file-name", desc = "A file name, with the  prefix.", trim = true, nilIfEmpty = true, },			group = { type = "string", required = true, desc = "A header for the given row in the navbox.", trim = true, nilIfEmpty = true, },			links = { type = "content", required = true, desc = "A comma-separated list of links for the given row.", trim = true, nilIfEmpty = true, split = true, },			footer = { type = "content", desc = "The navbox footer. Usually contains links to relevant categories.", trim = true, nilIfEmpty = true, },		},	}, }

return p