Module:Variable arguments

From Xenharmonic Wiki
Revision as of 13:22, 3 March 2025 by ArrowHead294 (talk | contribs)
Jump to navigation Jump to search
Module documentation[view] [edit] [history] [purge]
This module should not be invoked directly; use its corresponding templates instead.

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

Introspection summary for Module:Variable arguments 
Functions provided (4)
Line Function Params
4 lua_banner (invokable) (frame)
36 nwr (invokable) (frame)
53 wikipedia (invokable) (frame)
87 breadcrumb (invokable) (frame)
Lua modules required (1)
Variable Module Functions used
mArguments Module:Arguments getArgs

No function descriptions were provided. The Lua code may have further information.


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

function p.lua_banner(frame)
    local args = mArguments.getArgs(frame, {
    	parentOnly = true
    })
	local out_str = ""
	local i = 0
	
	for k, v in pairs(args) do
		out_str = out_str .. string.format("* [[Module:%s]]\n", v)
		i = i + 1
	end
	
	out_str = out_str:sub(1, -2)
	
	if out_str == "" then
		out_str = "* [[Module:{{ROOTPAGENAME}}]]\n"
	end
	
	out_str = "<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", out_str)
		.. "|}</div>"
	return frame:preprocess(out_str)
end

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

function p.wikipedia(frame)
	local args = mArguments.getArgs(frame, {
		parentOnly = true
	})
	local out_str = ""
	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
			out_str = out_str .. "<div style=\"margin-left: 10px;\">"
				.. string.format("'''[[wikipedia:%s|%s]]'''", v, v)
				.. "</div>\n"
		end
		i = i + 1
	end
	
	if out_str == "" then
		local arpn = frame:preprocess("{{#if: {{ARTICLESPACE}}|{{ARTICLESPACE}}{{colon}}|}}{{ROOTPAGENAME}}")
		out_str = "<div style=\"margin-left: 10px;\">"
			.. string.format("'''[[wikipedia:%s|%s]]'''", arpn, arpn)
			.. "</div>\n" .. out_str
	end
	
	out_str = "<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"), out_str)
	    .. "{{clear}}</div>"
	return frame:preprocess(out_str)
end

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

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

    out_str = out_str:sub(1, -11)
	
	if out_str == "" then
		out_str = "[[{{#titleparts: {{FULLPAGENAME}}|-1}}]]"
	end
	
	out_str = "<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>", out_str)
		.. "</div></div>"
	return frame:preprocess(out_str)
end

return p