User:Fae/Sandbox/Module:Tabs

From Zelda Wiki, the Zelda encyclopedia
Revision as of 08:08, 7 May 2024 by Fae (talk | contribs) (Created page with "local p = {} local utilsArg = require("Module:UtilsArg") local utilsLayout = require("Module:UtilsLayout") 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 .. err.categoryText end return result end function p.printTabs(args) local tabData = {} for i, tab in ipairs(args.tabs) do local tabContent = tab.content if tabContent and mw.text.killMarkers(t...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

local p = {}

local utilsArg = require("Module:UtilsArg") local utilsLayout = require("Module:UtilsLayout")

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 .. err.categoryText end return result end

function p.printTabs(args) local tabData = {} for i, tab in ipairs(args.tabs) do local tabContent = tab.content if tabContent and mw.text.killMarkers(tabContent) == "" then tabContent = mw.text.unstripNoWiki(tabContent) tabContent = mw.getCurrentFrame():preprocess(tabContent) end table.insert(tabData, { label = tab.tab, content = tabContent, tooltip = tab.tooltip, }) end local result = utilsLayout.tabs(tabData, { align = args.align, default = args.default, tabOptions = { columns = args.columns, position = args.position, stretch = args.distribution == "stretch", }, contentOptions = { fixedHeight = args.position == "bottom", alignVertical = args.position == "bottom" and "center", }, }) return result end

p.Templates = { Tabs = { description = "Displays content in separate tabs.", purpose = "Displays content in separate tabs. See also Template:Game Tabs.", format = "block", repeatedGroup = { name = "tabs", params = {"tab", "tooltip", "content"}, }, 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 stretch, the tab buttons will stretch to fill the space afforded by the tab container. Incompatible with columns.", 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 = "", tooltip1 = "Spring", content1 = "",

tab2 = "", tooltip2 = "Summer", content2 = "",

tab3 = "", tooltip3 = "Autumn", content3 = "",

tab4 = "", tooltip4 = "Winter", content4 = "", }, { desc = "Wrap content in nowiki tabs when it contains pipe characters (e.g. tables)", args = { tab1= "Tab 1", content1= [[

{| class="wikitable" ! Header 1 ! Header 2 |- | A || B |- | C || D |} ]], tab2= "Tab 2", content2= [[

{| class="wikitable" ! Header 1 ! Header 2 |- | D || E |- | F || G |} ]], } }, }, }, }

return p