Module:Variable arguments: Difference between revisions

(Variable argument functions)
 
mNo edit summary
 
(16 intermediate revisions by the same user not shown)
Line 1: Line 1:
local mArguments = require("Module:Arguments")
local mArguments = require("Module:Arguments")
local yesno = require("Module:Yesno")
local p = {}
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:" .. frame:preprocess("{{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)
function p.breadcrumb(frame)
Line 31: Line 7:
     parentOnly = true
     parentOnly = true
     })
     })
local out_str = ""
    local debugg = frame.args.debug_mode or args.debug_mode
local result = ""
local i = 0
local i = 0
    local pname = ""
for k, v in pairs(args) do
for k, v in pairs(args) do
out_str = out_str .. "[[" .. v .. "]] | "
        pname = pname .. v
result = result .. (v == debugg and "" or string.format("[[%s|%s]] {{pipe}} ", pname, v))
i = i + 1
i = i + 1
        pname = pname .. "/"
end
end
    result = result:sub(1, -11)
if out_str == "" then
if result == "" or result == nil then
out_str = frame:preprocess("[[{{#titleparts: {{FULLPAGENAME}}|-1}}]]")
result = "[[{{#titleparts: {{FULLPAGENAME}}|-1}}]]"
end
end
out_str = "<div id=\"contentSub\">"
result = "<div id=\"contentSub\">\n"
.. "<div style=\"margin: 0.5em;\"></div>"
.. "<div id=\"mw-content-subtitle\">\n"
.. "<div class=\"nomobile\" style=\"margin: -0.8em;\"></div>"
.. "<div style=\"margin: 0.5em;\"></div>\n"
.. "<div style=\"margin: 0em;\"><span class=\"subpages\">&lt; " .. out_str
.. "<div class=\"nomobile\" style=\"margin: -0.8em;\"></div>\n"
.. "</span></div></div>"
.. string.format("<div class=\"subpages\" style=\"margin-top: -0.1em;\">&lt; <bdi dir=\"ltr\">%s</bdi></div>\n", result)
return out_str
.. "</div>\n</div>{{#if: {{ARTICLESPACE}}||[[Category:Article subpages]]}}"
return frame:preprocess(yesno(debugg) == true and "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>" or result)
end
end


return p
return p

Latest revision as of 12:56, 13 May 2025

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 yesno = require("Module:Yesno")
local p = {}

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

    local pname = ""
	
	for k, v in pairs(args) do
        pname = pname .. v
		result = result .. (v == debugg and "" or 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\">\n"
		.. "<div id=\"mw-content-subtitle\">\n"
		.. "<div style=\"margin: 0.5em;\"></div>\n"
		.. "<div class=\"nomobile\" style=\"margin: -0.8em;\"></div>\n"
		.. string.format("<div class=\"subpages\" style=\"margin-top: -0.1em;\">&lt; <bdi dir=\"ltr\">%s</bdi></div>\n", result)
		.. "</div>\n</div>{{#if: {{ARTICLESPACE}}||[[Category:Article subpages]]}}"
	return frame:preprocess(yesno(debugg) == true and "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>" or result)
end

return p