Module:Variable arguments

From Xenharmonic Wiki
Jump to navigation Jump to search
Test Template Info-Icon - Version (2).svg Module documentation[view] [edit] [history] [purge]

This module is used to store functions for templates that take a variable number of arguments but do not use Module:Labelled list hatnote:


local mArguments = require("Module:Arguments")
local p = {}

function p.lua_banner(frame)
    local args = mArguments.getArgs(frame, {
    	parentOnly = true
    })
	local result = ""
	local i = 0
	
	for k, v in pairs(args) do
		result = result .. string.format("* [[Module:%s]]\n", v)
		i = i + 1
	end
	
	result = result:sub(1, -2)
	
	if result == "" or result == nil then
		result = "* [[Module:{{ROOTPAGENAME}}]]\n"
	end
	
	result = "<div style=\"border-collapse: collapse; border: 1px solid #a2a9b1;"
		.. " background-color: #f8f9fa; box-sizing: border-box; clear: right; "
		.. "color: #202122; float: right; font-size: 16px; margin: 0 0 4px 4px; width: 238px;\">\n"
		.. "{|\n"
		.. "|-\n"
		.. "| <span style=\"line-height: 110%; display: inline-block; "
		.. "margin: 0.125em 0em 0.125em 0.792em;\">[[File:Lua-Logo.svg|30px]]</span>"
		.. " || <span style=\"display: inline-block; font-size: 0.88em; "
		.. "line-height: 110%; padding: 0.22em 0.22em 0.22em 0.792em;\">"
		.. string.format("This template uses {{w|WP:Lua|Lua}}:\n%s</span>\n", result)
		.. "|}</div>"
	return frame:preprocess(result)
end

function p.nwr(frame)
	local args = mArguments.getArgs(frame, {
    	parentOnly = true
    })
	local result = ""
	local i = 0
	
	for k, v in pairs(args) do
		result = result .. string.format("<span style=\"white-space: nowrap;\">%s</span>, ",
			string.gsub(v, "^%s*(.-)%s*$", "%1"))
		i = i + 1
	end
	
	result = result:sub(1, -3)
	return frame:preprocess(result)
end

function p.wikipedia(frame)
	local args = mArguments.getArgs(frame, {
		parentOnly = true
	})
	local result = ""
	local i = 0
	
	for k, v in pairs(args) do
		v = string.gsub(v, "^%s*(.-)%s*$", "%1")
		
		if string.lower(v) ~= "false" and string.lower(v) ~= "true" then
			result = result .. string.format("<div style=\"margin-left: 10px;\">'''{{w|%s}}'''</div>\n", v)
		end
		i = i + 1
	end
	
	if result == "" then
		result = "<div style=\"margin-left: 10px;\">'''{{w|{{ARTICLEROOTPAGENAME}}}}'''</div>\n" .. result
	end
	
	result = "<div style=\"background: #f9f9f9; border: 1px solid #aaa; clear: right; float: right; "
		.. "font-size: 90%; width: 300px; margin: 0 0 4px 4px; padding: 4px; text-align: left;\">\n"
	    .. "<div style=\"float: left;\">[[File:Wikipedia-logo.png|44px|none|link=|alt=]]</div>\n"
	    .. "<div style=\"margin-left: 60px;\">"
	    .. string.format("English [[Wikipedia:Main Page|Wikipedia]] has %s on:\n%s</div>", (i > 1 and "articles" or "an article"), result)
	    .. "{{clear}}</div>"
	return frame:preprocess(result)
end

function p.breadcrumb(frame)
	local args = mArguments.getArgs(frame, {
    	parentOnly = true
    })
	local result = ""
	local i = 0

    local pname = ""
	
	for k, v in pairs(args) do
        pname = pname .. v
		result = result .. string.format("[[%s|%s]] {{pipe}} ", pname, v)
		i = i + 1
        pname = pname .. "/"
	end

    result = result:sub(1, -11)
	
	if result == "" or result == nil then
		result = "[[{{#titleparts: {{FULLPAGENAME}}|-1}}]]"
	end
	
	result = "<div id=\"contentSub\">"
		.. "<div style=\"margin: 0.5em;\"></div>"
		.. "<div class=\"nomobile\" style=\"margin: -0.8em;\"></div>"
		.. "<div style=\"margin: 0em;\">"
		.. string.format("<span class=\"subpages\">&lt; %s</span>", result)
		.. "</div></div>"
	return frame:preprocess(result)
end

return p