Module:Navbar: Difference between revisions
Jump to navigation
Jump to search
ArrowHead294 (talk | contribs) mNo edit summary |
ArrowHead294 (talk | contribs) mNo edit summary |
||
Line 36: | Line 36: | ||
local thresh = 5 | local thresh = 5 | ||
local | local idxn1 = x - 1 | ||
local idxn2 = x - 2 | |||
local idxn3 = x - 3 | |||
local idx1 = x + 1 | |||
local idx2 = x + 2 | |||
local idx3 = x + 3 | |||
local result = "<br />{{Navbox" | |||
.. "|name=Navbox Lumatone" | .. "|name=Navbox Lumatone" | ||
.. "|Title=[[Lumatone|Lumatone mappings]]" | .. "|Title=[[Lumatone|Lumatone mappings]]" | ||
.. "|Data 1={{centre|" | .. "|Data 1={{centre|" | ||
if x >= thresh + 4 then | |||
result = result .. "'''←''' " | |||
end | |||
.. "'''Lumatone mapping for | |||
.. "[[Lumatone mapping for | if x >= thresh + 3 then | ||
.. "[[Lumatone mapping for | result = result .. string.format("[[Lumatone mapping for %sedo|%sedo]] • ", idxn3, idxn3) | ||
.. "[[Lumatone mapping for | end | ||
.. "}}" | |||
if x >= thresh + 2 then | |||
result = result .. string.format("[[Lumatone mapping for %sedo|%sedo]] • ", idxn2, idxn2) | |||
end | |||
if x >= thresh + 1 then | |||
result = result .. string.format("[[Lumatone mapping for %sedo|%sedo]] • ", idxn1, idxn1) | |||
end | |||
result = result .. string.format("'''Lumatone mapping for %sedo''' • " | |||
.. "[[Lumatone mapping for %sedo|%sedo]] • " | |||
.. "[[Lumatone mapping for %sedo|%sedo]] • " | |||
.. "[[Lumatone mapping for %sedo|%sedo]] '''→'''}}" | |||
.. "}}", x, idx1, idx1, idx2, idx2, idx3, idx3) | |||
if string.lower(arpn) ~= "template:navbox lumatone" then | if string.lower(arpn) ~= "template:navbox lumatone" then | ||
result = result .. " [[Category:Lumatone mappings]] [[Category:" .. x .. "edo]]" | |||
end | end | ||
return frame:preprocess(debugg == true and "<pre>" .. | return frame:preprocess(debugg == true and "<pre>" .. result .. "</pre>" or result) | ||
end | end | ||
function p.frac_octave(frame) | function p.frac_octave(frame) | ||
local | local arpn = frame:preprocess("{{ARTICLEROOTPAGENAME}}") | ||
local debugg = yesno(frame.args["debug"]) | local debugg = yesno(frame.args["debug"]) | ||
local a = | local a = arpn:match("(%d+)%a+[%s%-]*[Oo]ctave%s*[Tt]emperament[s]?") | ||
local x = tonumber(frame.args["f"]) or tonumber(a) | local x = tonumber(frame.args["f"]) or tonumber(a) | ||
local thresh = 2 | |||
local idxn1 = ordinal(x - 1) | |||
local idxn2 = ordinal(x - 2) | |||
local idxn3 = ordinal(x - 3) | |||
local idxn4 = ordinal(x - 4) | |||
local idx1 = ordinal(x + 1) | |||
local idx2 = ordinal(x + 2) | |||
local idx3 = ordinal(x + 3) | |||
local idx4 = ordinal(x + 4) | |||
local result = "<br />{{Navbox" | |||
.. "| name=Navbox fractional-octave" | |||
.. "| Title=[[Fractional-octave temperaments]]" | |||
.. "| Data 1={{centre|" | |||
if x >= thresh + 4 then | |||
result = result .. "'''←''' " | |||
end | |||
if x >= thresh + 3 then | |||
result = result .. string.format("[[%s-octave temperaments|%s]] • ", idxn4, idxn4) | |||
end | |||
if x >= thresh + 2 then | |||
.. | result = result .. string.format("[[%s-octave temperaments|%s]] • ", idxn3, idxn3) | ||
end | |||
if x >= thresh + 1 then | |||
.. ( | result = result .. string.format("[[%s-octave temperaments|%s]] • ", idxn2, idxn2) | ||
end | |||
.. ( | |||
if x >= thresh then | |||
result = result .. string.format("[[%s-octave temperaments|%s]] • ", idxn1, idxn1) | |||
.. "[[ | end | ||
.. "[[ | |||
.. "[[ | result = result .. string.format("'''%s-octave''' • " | ||
.. "[[ | .. "[[%s-octave temperaments|%s]] • " | ||
.. "}}" | .. "[[%s-octave temperaments|%s]] • " | ||
.. "[[%s-octave temperaments|%s]] • " | |||
.. "[[%s-octave temperaments|%s]] '''→'''}}" | |||
.. "}}", ordinal(x), idx1, idx1, idx2, idx2, idx3, idx3, idx4, idx4) | |||
return frame:preprocess(debugg == true and "<pre>" .. | return frame:preprocess(debugg == true and "<pre>" .. result .. "</pre>" or result) | ||
end | end | ||
return p | return p |
Revision as of 13:48, 6 March 2025
This module is used to store functions for templates that generate a navigation bar:
Template:Navbar also uses this module, even though it only generates View/Talk/Edit links.
To include this module in other modules, use local navbar = require("Module:Navbar")._navbar
.
See also
local ordinal = require("Module:Ordinal")._ordinal
local yesno = require("Module:yesno")
local p = {}
function p._navbar(name, mode, text, namespace)
mode = mode or ""
text = (text == nil and "" or text .. " ")
namespace = namespace or "Template"
local p_name = string.format("%s:%s", namespace, name)
local p_talk_name = string.format("%s talk:%s", namespace, name)
local p_edit_name = "special:editpage/" .. p_name
local s = ((mode == "v" or mode == "vmini") and "<br />" or " • ")
return "<span style=\"font-size: 0.75em; font-weight: normal; font-style: normal;\">"
.. text
.. string.format(((mode == "mini" or mode == "vmini") and "[[%s|V]]%s[[%s|T]]%s[[%s|E]]" or "[[%s|View]]%s[[%s|Talk]]%s[[%s|Edit]]"),
p_name, s, p_talk_name, s, p_edit_name)
.. "</span>"
end
function p.navbar(frame)
local name = frame.args["name"]
local namespace = frame.args["namespace"]
local mode = frame.args["mode"]
local text = frame.args["text"]
return p._navbar(name, mode, text, namespace)
end
function p.lumatone_map(frame)
local arpn = frame:preprocess("{{ARTICLEROOTPAGENAME}}")
local debugg = yesno(frame.args["debug"])
local a = arpn:match("[Ll]umatone%s*[Mm]apping%s*[Ff]or%s*(%d+)%s*[Ee][Dd][2Oo]")
local x = tonumber(frame.args["edo"]) or tonumber(a)
local thresh = 5
local idxn1 = x - 1
local idxn2 = x - 2
local idxn3 = x - 3
local idx1 = x + 1
local idx2 = x + 2
local idx3 = x + 3
local result = "<br />{{Navbox"
.. "|name=Navbox Lumatone"
.. "|Title=[[Lumatone|Lumatone mappings]]"
.. "|Data 1={{centre|"
if x >= thresh + 4 then
result = result .. "'''←''' "
end
if x >= thresh + 3 then
result = result .. string.format("[[Lumatone mapping for %sedo|%sedo]] • ", idxn3, idxn3)
end
if x >= thresh + 2 then
result = result .. string.format("[[Lumatone mapping for %sedo|%sedo]] • ", idxn2, idxn2)
end
if x >= thresh + 1 then
result = result .. string.format("[[Lumatone mapping for %sedo|%sedo]] • ", idxn1, idxn1)
end
result = result .. string.format("'''Lumatone mapping for %sedo''' • "
.. "[[Lumatone mapping for %sedo|%sedo]] • "
.. "[[Lumatone mapping for %sedo|%sedo]] • "
.. "[[Lumatone mapping for %sedo|%sedo]] '''→'''}}"
.. "}}", x, idx1, idx1, idx2, idx2, idx3, idx3)
if string.lower(arpn) ~= "template:navbox lumatone" then
result = result .. " [[Category:Lumatone mappings]] [[Category:" .. x .. "edo]]"
end
return frame:preprocess(debugg == true and "<pre>" .. result .. "</pre>" or result)
end
function p.frac_octave(frame)
local arpn = frame:preprocess("{{ARTICLEROOTPAGENAME}}")
local debugg = yesno(frame.args["debug"])
local a = arpn:match("(%d+)%a+[%s%-]*[Oo]ctave%s*[Tt]emperament[s]?")
local x = tonumber(frame.args["f"]) or tonumber(a)
local thresh = 2
local idxn1 = ordinal(x - 1)
local idxn2 = ordinal(x - 2)
local idxn3 = ordinal(x - 3)
local idxn4 = ordinal(x - 4)
local idx1 = ordinal(x + 1)
local idx2 = ordinal(x + 2)
local idx3 = ordinal(x + 3)
local idx4 = ordinal(x + 4)
local result = "<br />{{Navbox"
.. "| name=Navbox fractional-octave"
.. "| Title=[[Fractional-octave temperaments]]"
.. "| Data 1={{centre|"
if x >= thresh + 4 then
result = result .. "'''←''' "
end
if x >= thresh + 3 then
result = result .. string.format("[[%s-octave temperaments|%s]] • ", idxn4, idxn4)
end
if x >= thresh + 2 then
result = result .. string.format("[[%s-octave temperaments|%s]] • ", idxn3, idxn3)
end
if x >= thresh + 1 then
result = result .. string.format("[[%s-octave temperaments|%s]] • ", idxn2, idxn2)
end
if x >= thresh then
result = result .. string.format("[[%s-octave temperaments|%s]] • ", idxn1, idxn1)
end
result = result .. string.format("'''%s-octave''' • "
.. "[[%s-octave temperaments|%s]] • "
.. "[[%s-octave temperaments|%s]] • "
.. "[[%s-octave temperaments|%s]] • "
.. "[[%s-octave temperaments|%s]] '''→'''}}"
.. "}}", ordinal(x), idx1, idx1, idx2, idx2, idx3, idx3, idx4, idx4)
return frame:preprocess(debugg == true and "<pre>" .. result .. "</pre>" or result)
end
return p