Module:Sidebar
- This module implements a metatemplate, and may be invoked by templates using its corresponding template Template:Sidebar, or used directly from other modules.
Module:Sidebar is a module that implements the {{Sidebar}} template. Sidebar templates can be made by using the template or by calling the _sidebar function from another module.
On templates, you can create a sidebar by using {{Sidebar}}, which calls this module's wrapper function.
local sidebar = require("Module:Sidebar")._sidebar to create a sidebar.
| Introspection summary for Module:Sidebar | |||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
| ||||||||||||||||||
No function descriptions were provided. The Lua code may have further information.
-- This module follows [[User:Ganaram inukshuk/Provisional style guide for Lua]]
local getArgs = require("Module:Arguments").getArgs
local tiu = require("Module:Template input utils")
local p = {}
-- Not to be confused with the infobox; the sidebar only has one column and is a
-- different color. Some infobox-ish templates use that style
-- Not to be confused with the sidebox either.
-- TODO: add float option?
-- "Main" function
function p._sidebar(args)
local title = args["Title" ]
local header = args["Header"]
local rows = args["Rows" ]
local footer = args["Footer"]
local float = args["Float" ] or "right"
-- Helper function; title
function sidebar_title()
local lines = {}
table.insert(lines, "|-")
table.insert(lines, string.format("! %s", title))
return table.concat(lines, "\n")
end
-- Helper function; row
function sidebar_row(row_content)
local lines = {}
table.insert(lines, "|-")
table.insert(lines, string.format("| %s", row_content))
return table.concat(lines, "\n")
end
-- Helper function; header/footer
function header_footer_row(row_content)
local lines = {}
table.insert(lines, "|-")
table.insert(lines, string.format('| style="font-size: 80%%;" | %s', row_content))
return table.concat(lines, "\n")
end
-- Boilerplate and start of table
local lines = {}
table.insert(lines, string.format('<div class="toccolours" style="float: %s; margin: 0px 0px 4px 4px; text-align: center">', float))
table.insert(lines, '{| class="none"')
table.insert(lines, "|-")
-- Title
if title then table.insert(lines, sidebar_title()) end
-- Header
if header then table.insert(lines, header_footer_row(header)) end
-- Rows
for i = 1, #rows do table.insert(lines, sidebar_row(rows[i])) end
-- Footer
if footer then table.insert(lines, header_footer_row(footer)) end
-- End of table
table.insert(lines, "|}")
table.insert(lines, "</div>")
return table.concat(lines, "\n")
end
-- Wrapper function
function p.sidebar(frame)
local args = getArgs(frame)
-- Preprocess rows
args["Rows"] = tiu.numbered_args_to_table(args, 20, "Row %d")
return frame:preprocess(p._sidebar(args))
end
return p