Module:Variable arguments: Difference between revisions

From Xenharmonic Wiki
Jump to navigation Jump to search
ArrowHead294 (talk | contribs)
mNo edit summary
ArrowHead294 (talk | contribs)
mNo edit summary
Line 6: Line 6:
     parentOnly = true
     parentOnly = true
     })
     })
local out_str = ""
local result = ""
local i = 0
local i = 0
for k, v in pairs(args) do
for k, v in pairs(args) do
out_str = out_str .. string.format("* [[Module:%s]]\n", v)
result = result .. string.format("* [[Module:%s]]\n", v)
i = i + 1
i = i + 1
end
end
out_str = out_str:sub(1, -2)
result = result:sub(1, -2)
if out_str == "" or out_str == nil then
if result == "" or result == nil then
out_str = "* [[Module:{{ROOTPAGENAME}}]]\n"
result = "* [[Module:{{ROOTPAGENAME}}]]\n"
end
end
out_str = "<div style=\"border-collapse: collapse; border: 1px solid #a2a9b1;"
result = "<div style=\"border-collapse: collapse; border: 1px solid #a2a9b1;"
.. " background-color: #f8f9fa; box-sizing: border-box; clear: right; "
.. " background-color: #f8f9fa; box-sizing: border-box; clear: right; "
.. "color: #202122; float: right; font-size: 16px; margin: 0 0 4px 4px; width: 238px;\">\n"
.. "color: #202122; float: right; font-size: 16px; margin: 0 0 4px 4px; width: 238px;\">\n"
Line 29: Line 29:
.. " || <span style=\"display: inline-block; font-size: 0.88em; "
.. " || <span style=\"display: inline-block; font-size: 0.88em; "
.. "line-height: 110%; padding: 0.22em 0.22em 0.22em 0.792em;\">"
.. "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)
.. string.format("This template uses {{w|WP:Lua|Lua}}:\n%s</span>\n", result)
.. "|}</div>"
.. "|}</div>"
return frame:preprocess(out_str)
return frame:preprocess(result)
end
end


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


Line 55: Line 55:
parentOnly = true
parentOnly = true
})
})
local out_str = ""
local result = ""
local i = 0
local i = 0
Line 62: Line 62:
if string.lower(v) ~= "false" and string.lower(v) ~= "true" then
if string.lower(v) ~= "false" and string.lower(v) ~= "true" then
out_str = out_str .. "<div style=\"margin-left: 10px;\">"
result = result .. "<div style=\"margin-left: 10px;\">"
.. string.format("'''[[wikipedia:%s|%s]]'''", v, v)
.. string.format("'''[[wikipedia:%s|%s]]'''", v, v)
.. "</div>\n"
.. "</div>\n"
Line 69: Line 69:
end
end
if out_str == "" then
if result == "" then
local arpn = frame:preprocess("{{ARTICLEROOTPAGENAME}}")
local arpn = frame:preprocess("{{ARTICLEROOTPAGENAME}}")
out_str = "<div style=\"margin-left: 10px;\">"
result = "<div style=\"margin-left: 10px;\">"
.. string.format("'''[[wikipedia:%s|%s]]'''", arpn, arpn)
.. string.format("'''[[wikipedia:%s|%s]]'''", arpn, arpn)
.. "</div>\n" .. out_str
.. "</div>\n" .. result
end
end
out_str = "<div style=\"background: #f9f9f9; border: 1px solid #aaa; clear: right; float: right; "
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"
.. "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=\"float: left;\">[[File:Wikipedia-logo.png|44px|none|link=|alt=]]</div>\n"
    .. "<div style=\"margin-left: 60px;\">"
    .. "<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)
    .. string.format("English [[Wikipedia:Main Page|Wikipedia]] has %s on:\n%s</div>", (i > 1 and "articles" or "an article"), result)
    .. "{{clear}}</div>"
    .. "{{clear}}</div>"
return frame:preprocess(out_str)
return frame:preprocess(result)
end
end


Line 89: Line 89:
     parentOnly = true
     parentOnly = true
     })
     })
local out_str = ""
local result = ""
local i = 0
local i = 0


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


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


return p
return p

Revision as of 14:42, 4 March 2025

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 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 .. "<div style=\"margin-left: 10px;\">"
				.. string.format("'''[[wikipedia:%s|%s]]'''", v, v)
				.. "</div>\n"
		end
		i = i + 1
	end
	
	if result == "" then
		local arpn = frame:preprocess("{{ARTICLEROOTPAGENAME}}")
		result = "<div style=\"margin-left: 10px;\">"
			.. string.format("'''[[wikipedia:%s|%s]]'''", arpn, arpn)
			.. "</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