Module:Template shortcuts

From Uncyclopedia, the content-free encyclopedia
Jump to navigation Jump to search

Documentation for this module may be created at Module:Template shortcuts/doc

-- This module implements [[Template:Template shortcuts]]
local compressSparseArray = require('Module:TableTools').compressSparseArray
local p = {}

function p.main(frame)
	local args = require('Module:Arguments').getArgs(frame)
	local separator = '<br />'
	local header = '<div id="shortcuts" class="noprint" style="border:1px solid #999; background:#fff; margin:0 0 .5em 1em; text-align:center; padding:5px; float:right; font-size:smaller; font-weight:bold;"> [[Uncyclopedia:Shortcut|Shortcut(s)]]:<br />'
	local footer = '</div>'
	local listItems = {}
	-- Discard empty arguments and named arguments
	local shortcuts = compressSparseArray(args)
	-- Iterate over shortcuts
	for i, shortcut in ipairs(shortcuts) do
			listItems[i] = string.format("&#123;&#123;[[Template:%s|%s]]&#125;&#125;", shortcut, shortcut)
	end
	return header .. table.concat(listItems, separator) .. footer
end

return p