User:Fae/Sandbox/Module:Tabs: Difference between revisions

From Zelda Wiki, the Zelda encyclopedia
Jump to navigation Jump to search
(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...")
 
(Replaced content with "{{Delete}}")
Tag: Replaced
 
Line 1: Line 1:
local p = {}
{{Delete}}
 
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 <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]]",
},
{
desc = "Wrap content in <code>nowiki</code> tabs when it contains pipe characters (e.g. tables)",
args = {
tab1= "Tab 1",
content1=
[[
 
<nowiki>
{| class="wikitable"
! Header 1
! Header 2
|-
| A || B
|-
| C || D
|}
</nowiki>]],
tab2= "Tab 2",
content2=
[[
 
<nowiki>
{| class="wikitable"
! Header 1
! Header 2
|-
| D || E
|-
| F || G
|}
</nowiki>]],
}
},
},
},
}
 
return p

Latest revision as of 08:11, 7 May 2024

This page may meet Zelda Wiki's criteria for deletion.