Module:Sidebar

From Xenharmonic Wiki
Jump to navigation Jump to search
Module documentation[view] [edit] [history] [purge]
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.

On modules, you can include local sidebar = require("Module:Sidebar")._sidebar to create a sidebar.
Introspection summary for Module:Sidebar 
Functions provided (2)
Line Function Params
16 _sidebar (main) (args)
85 sidebar (invokable) (frame)
Lua modules required (3)
Variable Module Functions used
getArgs Module:Arguments getArgs
navbar Module:Navbar _navbar
tiu Module:Template input utils numbered_args_to_table

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 navbar  = require("Module:Navbar")._navbar
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: use templatestyles

-- "Main" function
function p._sidebar(args)
	local title  = args["Title"] or "Sidebar Title"
	local header = args["Header Row"]
	local rows   = args["Rows"]
	local footer = args["Footer Row"]
	local float  = args["float"] or "right"
	local name   = args["name"]
	
	-- 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
	
	-- Helper function; navbar row
	function navbar_row()
		local lines = {}
		table.insert(lines, '|-')
		table.insert(lines, '| style="text-align: center;" | ' .. navbar(name, "mini", ""))
		
		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
	
	if name then table.insert(lines, navbar_row()) 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