Module:Variable arguments: Difference between revisions

ArrowHead294 (talk | contribs)
New list for of arbitrary-argument template functions
 
ArrowHead294 (talk | contribs)
mNo edit summary
 
(148 intermediate revisions by 2 users not shown)
Line 1: Line 1:
local p = {}
local mArguments = require("Module:Arguments")
local mArguments = require("Module:Arguments")
local p = {}
local utils = require("Module:Utils")
local yesno = require("Module:Yesno")
 
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 == nil or utils.trim(result) == "" then
result = "[[{{#titleparts: {{FULLPAGENAME}}|-1}}]]"
end
result = "<div class=\"mw-content-subtitle2\">"
.. "<div class=\"breadcrumb-article\">"
.. string.format("<div class=\"subpages\">&lt; <bdi dir=\"ltr\">%s</bdi></div>", result)
.. "</div></div>"
.. "{{#if: {{ARTICLESPACE}}||[[Category:Article subpages]]}}"
.. mw.getCurrentFrame():extensionTag("templatestyles", "", {
src = "Template:Breadcrumb/styles.css"
})
if yesno(debugg) == true then
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>"
end
return frame:preprocess(result)
end
 
function p.lua_banner(frame)
local args = mArguments.getArgs(frame, {
    parentOnly = true
    })
    local debugg = frame.args.debug_mode or args.debug_mode
    local fmt = "* [[Module: %s]]\n"
    local namespace = string.lower(frame:preprocess("{{NAMESPACE}}"))
local result = ""
local i = 1
for k, v in pairs(args) do
result = result .. (v == debugg and "" or string.format(fmt, frame:preprocess(string.format("{{ucfirst: %s}}", v))))
i = i + 1
end
result = result:sub(1, -2)
if result == nil or utils.trim(result) == "" then
local rpn = frame:preprocess("{{ROOTPAGENAME}}")
result = string.format(fmt, rpn)
end
result = "{{sidebox\n| image = Lua-Logo.svg\n| image size = 30px\n| text = "
.. string.format("%s:\n%s\n",
(namespace == "module"
and "This module depends on the following other modules"
or "This template uses {{wlink|Lua|s=wp}}"),
result)
.. "}}"
 
if yesno(debugg) == true then
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>"
end
return frame:preprocess(result)
end
 
function p.nwr(frame)
local args = mArguments.getArgs(frame, {
    parentOnly = true
    })
    local debugg = frame.args.debug_mode or args.debug_mode
local result = ""
local i = 0
for k, v in pairs(args) do
result = result .. (v == debugg and "" or
string.format("<span style=\"white-space: nowrap;\">%s</span>, ", utils.trim(v)))
i = i + 1
end
result = result:sub(1, -3)
if result == nil or utils.trim(result) == "" then
return ""
end
if yesno(debugg) == true then
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>"
end
return frame:preprocess(result)
end


function p.modlink(frame)
function p.wikipedia(frame)
    local args = mArguments.getArgs(frame, {
local args = mArguments.getArgs(frame, {
     parentOnly = true
     parentOnly = true
     })
     })
local out_str = ""
    local debugg = frame.args.debug_mode or args.debug_mode
    local fmt = "<div>'''{{wlink|%s}}'''</div>\n"
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 .. "[[Module:" .. v .. "]]" .. ", "
v = string.gsub(v, "^%s*(.-)%s*$", "%1")
i = k
if string.lower(v) ~= "false" and string.lower(v) ~= "true" then
result = result .. (v == debugg and "" or string.format(fmt, v))
end
i = i + 1
end
if result == nil or utils.trim(result) == "" then
local arpn = frame:preprocess("{{ARTICLEROOTPAGENAME}}")
result = string.format(fmt, arpn)
end
result = "<div class=\"wikibanner\">\n"
    .. "<div class=\"wikibanner-image\">[[File:Wikipedia-logo.png|44px|none|link=|alt=]]</div>\n"
    .. "<div class=\"wikibanner-text\">"
    .. string.format("English [[Wikipedia:Main Page|Wikipedia]] has %s on:\n%s</div>", (i > 1 and "articles" or "an article"), result)
    .. "{{clear}}</div>"
    .. mw.getCurrentFrame():extensionTag("templatestyles", "", {
src = "Template:Wikipedia/styles.css"
})
if yesno(debugg) == true then
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>"
end
end
out_str = out_str:sub(1, -3)
.. " &ndash; The "
return frame:preprocess(result)
.. string.gsub("module that implement", "()", {[((i > 1) and {7} or {22})[1]] = "s"})
.. " the functionality."
return out_str
end
end


return p
return p