Module:Variable arguments

From Stalburg Wiki
Revision as of 15:27, 27 February 2025 by ABC-DEFG (talk | contribs)
Jump to navigation Jump to search

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.modlink(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 .. "[[Module:" .. v .. "]]" .. ", "
		i = i + 1
	end
	
	out_str = out_str:sub(1, -3)
	
	if out_str == "" then
		out_str = "[[Module:{{ROOTPAGENAME}}]]"
	end
	
	out_str = out_str 
		.. " – the "
		.. string.gsub("module that implement", "()", {[((i > 1) and {7} or {22})[1]] = "s"})
		.. " the functionality."
	return 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 .. "[[" .. pname .. "|" .. v .. "]] {{pipe}} "
		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;\"><span class=\"subpages\">&lt; " .. out_str
		.. "</span></div></div>")
	return frame:preprocess(out_str)
end

return p