Zelda Wiki

Want to contribute to this wiki?
Sign up for an account, and get started!

Come join the Zelda Wiki community Discord server!

READ MORE

Zelda Wiki
Advertisement
This is the main module for the following templates:
local p = {}

local utilsArg = require("Module:UtilsArg")
local utilsMarkup = require("Module:UtilsMarkup")
local utilsLayout = require("Module:UtilsLayout")
local utilsTable = require("Module:UtilsTable")

function p.Main(frame)
	local args, err = utilsArg.parse(frame:getParent().args, p.Templates.Tabs)
	local result = p.printTabs(args)
	if err then
		result = result .. utilsMarkup.categories(err.categories)
	end
	return result
end

function p.printTabs(args)
	local tabs = utilsTable.map(args.tabs, function(tab)
		return {
			label = tab.tab,
			content = tab.content,
			tooltip = tab.tooltip,
		}
	end)
	local result = utilsLayout.tabs(tabs, {
		align = args.align,
		default = args.default,
		tabOptions = {
			columns = args.columns,
			position = args.position,
			stretch = args.distribution == "stretch",
		}
	})
	return result
end

p.Templates = {
	Tabs = {
		purpose = "Used to alternate among related views within the same context.",
		format = "block",
		repeatedGroup = {
			name = "tabs",
			params = {"tab", "tooltip", "content"},
			count = 8,
		},
		paramOrder = {"align", "columns", "default", "distribution", "position", "tab", "content"},
		params = {
			tab = {
				type = "string",
				required = true,
				desc = "The label for the tab button.",
				trim = true,
				nilIfEmpty = true,
			},
			content = {
				type = "string",
				required = true,
				desc = "The content to display for the tab.",
				trim = true,
				nilIfEmpty = true,
			},
			tooltip = {
				type = "string",
				desc = "Tooltip to display when hovering on the tab button. Must be plain text without markup.",
				trim = true,
				nilIfEmpty = true,
				canOmit = true,
			},
			align = {
				type = "string",
				enum = {"left", "center"},
				default = "left",
				desc = "Horizontal alignment of the tab container and its contents.",
				trim = true,
				nilIfEmpty = true,
				canOmit = true,
			},
			columns = {
				type = "number",
				desc = "A number. If specified, the tab buttons will attempt to arrange themselves in N columns of equal width.",
				trim = true,
				nilIfEmpty = true,
				canOmit = true,
			},
			default = {
				type = "number",
				default = 1,
				desc = "A number. The index of the default tab.",
				trim = true,
				nilIfEmpty = true,
				canOmit = true,
			},
			distribution = {
				type = "string",
				enum = {"stretch"},
				desc = "If set to <code>stretch</code>, the tab buttons will stretch to fill the space afforded by the tab container. Incompatible with <code>columns</code>.",
				trim = true,
				nilIfEmpty = true,
				canOmit = true,
			},
			position = {
				type = "string",
				enum = {"top", "bottom"},
				default = "top",
				desc = "The vertical positioning of the tab buttons in relation to their content.",
				trim = true,
				nilIfEmpty = true,
				canOmit = true,
			},
		},
		examples = {
			{
				tab1 = "Tab 1",
				content1 = "Content 1111111111111111111111111111111111",
				tab2 = "Tab 2",
				content2 = "Content 2222222222222222222222222222222222",
				tab3 = "Tab 3",
				content3 = "Content 3333333333333333333333333333333333",
			},
			{
				align = "center",
				
				tab1 = "Tab 1",
				content1 = "Content 1111111111111111111111111111111111",
				tooltip1 = "First Tab",
				
				tab2 = "Tab 2",
				content2 = "Content 2222222222222222222222222222222222",
				tooltip2 = "Second Tab",
				
				tab3 = "Tab 3",
				content3 = "Content 3333333333333333333333333333333333",
				tooltip3 = "Third Tab",
			},
			{
				align = "center",
				position = "bottom",
				default = 2,
				
				tab1 = "Tab 1",
				content1 = "Content 1111111111111111111111111111111111",
				
				tab2 = "Tab 2",
				content2 = "Content 2222222222222222222222222222222222",
				
				tab3 = "Tab 3",
				content3 = "Content 3333333333333333333333333333333333",
			},
			{
				distribution = "stretch",
				
				tab1 = "Tab 1",
				content1 = "Content 1111111111111111111111111111111111",
				
				tab2 = "Tab 2",
				content2 = "Content 2222222222222222222222222222222222",
				
				tab3 = "Tab 3",
				content3 = "Content 3333333333333333333333333333333333",
			},
			{
				align = "center",
				columns = 2,
				
				tab1 = "[[File:OOS Spring.png|link=]]",
				tooltip1 = "Spring",
				content1 = "[[File:Holodrum Spring.png|300px]]",
				
				tab2 = "[[File:OOS Summer.png|link=]]",
				tooltip2 = "Summer",
				content2 = "[[File:Holodrum Summer.png|300px]]",
				
				tab3 = "[[File:OOS Autumn.png|link=]]",
				tooltip3 = "Autumn",
				content3 = "[[File:Holodrum Autumn.png|300px]]",
				
				tab4 = "[[File:OOS Winter.png|link=]]",
				tooltip4 = "Winter",
				content4 = "[[File:Holodrum Winter.png|300px]]",
			}
		},
	},
}

return p
Advertisement