Module:Navbar: Difference between revisions

ArrowHead294 (talk | contribs)
mNo edit summary
ArrowHead294 (talk | contribs)
mNo edit summary
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local ordinal = require("Module:Ordinal")._ordinal
local ordinal = require("Module:Ordinal")._ordinal
local yesno = require("Module:yesno")
local yesno = require("Module:Yesno")
local p = {}


-- Main function called by navigation box templates
function p._navbar(name, mode, text, namespace)
function p._navbar(name, mode, text, namespace)
mode = mode or ""
mode = mode or ""
Line 10: Line 12:
local p_name = string.format("%s:%s", namespace, name)
local p_name = string.format("%s:%s", namespace, name)
local p_talk_name = string.format("%s talk:%s", namespace, name)
local p_talk_name = string.format("%s talk:%s", namespace, name)
local p_edit_name = "special:editpage/" .. p_name
local p_edit_name = "Special:EditPage/" .. p_name
local s = ((mode == "v" or mode == "vmini") and "<br />" or " &bull; ")
local s = " &bull; "
local links = (mode == mini and {"V", "T", "E"} or {"View", "Talk", "Edit"})
return "<span style=\"font-size: 0.75em; font-weight: normal; font-style: normal;\">"
return "<span style=\"font-size: 0.75em; font-weight: normal; font-style: normal;\">"
.. text
.. string.format("%s[[%s|%s]]%s[[%s|%s]]%s[[%s|%s]]",
.. 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]]"),
text, p_name, links[1], s, p_talk_name, links[2], s, p_edit_name, links[3])
p_name, s, p_talk_name, s, p_edit_name)
.. "</span>"
.. "</span>"
end
end


-- Wrapper function for [[Template:Navbar]]
function p.navbar(frame)
function p.navbar(frame)
local name = frame.args["name"]
local name = frame.args["name"]
Line 25: Line 28:
local mode = frame.args["mode"]
local mode = frame.args["mode"]
local text = frame.args["text"]
local text = frame.args["text"]
local debugg = frame.args["debug"]
local result = p._navbar(name, mode, text, namespace)
-- Debugger option
if debugg == true then
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>"
end
return p._navbar(name, mode, text, namespace)
return frame:preprocess(result)
end
end


-- Navbox for lumatone mappings
function p.lumatone_map(frame)
function p.lumatone_map(frame)
local arpn = frame:preprocess("{{ARTICLEROOTPAGENAME}}")
local debugg = yesno(frame.args["debug"])
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"]:match("(%d+)"))
local x = tonumber(frame.args["edo"]) or tonumber(a)
local thresh = 5
local thresh = 5
Line 43: Line 52:
local idx3 = x + 3
local idx3 = x + 3
local result = "<br />{{Navbox"
local result = "<br />{{Navbox\n"
.. "|name=Navbox Lumatone"
.. "| name = Navbox Lumatone\n"
.. "|Title=[[Lumatone|Lumatone mappings]]"
.. "| Title = [[Lumatone|Lumatone mappings]]\n"
.. "|Data 1={{centre|"
.. "| Data 1 = {{centre|"
if x >= thresh + 4 then
if x >= thresh + 4 then
Line 64: Line 73:
end
end
result = result .. string.format("'''Lumatone mapping for %sedo''' &bull; "
result = result
.. "[[Lumatone mapping for %sedo|%sedo]] &bull; "
.. string.format("'''Lumatone mapping for %sedo''' &bull; ", x)
.. "[[Lumatone mapping for %sedo|%sedo]] &bull; "
.. string.format("[[Lumatone mapping for %sedo|%sedo]] &bull; ", idx1, idx1)
.. "[[Lumatone mapping for %sedo|%sedo]] '''&rarr;'''}}"
.. string.format("[[Lumatone mapping for %sedo|%sedo]] &bull; ", idx2, idx2)
.. "}}", x, idx1, idx1, idx2, idx2, idx3, idx3)
.. string.format("[[Lumatone mapping for %sedo|%sedo]] '''&rarr;'''}}\n", idx3, idx3)
.. "}}"
 
-- Debugger option
if debugg == true then
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>"
end
if string.lower(arpn) ~= "template:navbox lumatone" then
return frame:preprocess(result)
result = result .. " [[Category:Lumatone mappings]] [[Category:" .. x .. "edo]]"
end
 
return frame:preprocess(debugg == true and "<pre>" .. result .. "</pre>" or result)
end
end


-- Navbox for fractional-octave temperaments
function p.frac_octave(frame)
function p.frac_octave(frame)
local arpn = frame:preprocess("{{ARTICLEROOTPAGENAME}}")
local arpn = frame:preprocess("{{ARTICLEROOTPAGENAME}}")
local debugg = yesno(frame.args["debug"])
local debugg = yesno(frame.args["debug"])
local a = arpn:match("(%d+)%a+[%s%-]*[Oo]ctave%s*[Tt]emperament[s]?")
local a = arpn:match("(%d+)%a+[%s%-]*")
local x = tonumber(frame.args["f"]) or tonumber(a)
local x = tonumber(frame.args["f"]) or tonumber(a)
local thresh = 2
local thresh = 2
Line 93: Line 105:
local idx4 = ordinal(x + 4)
local idx4 = ordinal(x + 4)
local result = "<br />{{Navbox"
local result = "<br />{{Navbox\n"
.. "| name=Navbox fractional-octave"
.. "| name = Navbox fractional-octave\n"
.. "| Title=[[Fractional-octave temperaments]]"
.. "| Title = [[Fractional-octave temperaments]]\n"
.. "| Data 1={{centre|"
.. "| Data 1 = {{centre|"
if x >= thresh + 4 then
if x >= thresh + 4 then
Line 118: Line 130:
end
end
result = result .. string.format("'''%s-octave''' &bull; "
result = result
.. "[[%s-octave temperaments|%s]] &bull; "
.. string.format("'''%s-octave''' &bull; ", ordinal(x))
.. "[[%s-octave temperaments|%s]] &bull; "
.. string.format("[[%s-octave temperaments|%s]] &bull; ", idx1, idx1)
.. "[[%s-octave temperaments|%s]] &bull; "
.. string.format("[[%s-octave temperaments|%s]] &bull; ", idx2, idx2)
.. "[[%s-octave temperaments|%s]] '''&rarr;'''}}"
.. string.format("[[%s-octave temperaments|%s]] &bull; ", idx3, idx3)
.. "}}", ordinal(x), idx1, idx1, idx2, idx2, idx3, idx3, idx4, idx4)
.. string.format("[[%s-octave temperaments|%s]] '''&rarr;'''}}\n", idx4, idx4)
.. "}}"


return frame:preprocess(debugg == true and "<pre>" .. result .. "</pre>" or result)
-- Debugger option
if debugg == true then
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>"
end
return frame:preprocess(result)
end
end


return p
return p