Module:Navbar: Difference between revisions

From Xenharmonic Wiki
Jump to navigation Jump to search
ArrowHead294 (talk | contribs)
mNo edit summary
ArrowHead294 (talk | contribs)
mNo edit summary
 
(46 intermediate revisions by 2 users 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 p = {}
-- Main function called by navigation box templates
 
function p._navbar(name, mode, text, namespace)
function p.navbar(name, mode, text)
mode = mode or ""
mode = mode or ""
text = text or ""
text = (text == nil and "" or text .. " ")
namespace = namespace or "Template"
return text .. "<span style=\"font-size: 0.75em; \">"
local p_name = string.format("%s:%s", namespace, name)
.. ((mode == "mini")
local p_talk_name = string.format("%s talk:%s", namespace, name)
and "[[Template:" .. name .. "|V]] &bull; " .. "[[Template talk:" .. name .. "|T]] &bull; " .. "[[Special:EditPage/Template:" .. name .. "|E]]"
local p_edit_name = "Special:EditPage/" .. p_name
or "[[Template:" .. name .. "|View]] &bull; " .. "[[Template talk:" .. name .. "|Talk]] &bull; " .. "[[Special:EditPage/Template:" .. name .. "|Edit]]")
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;\">"
.. string.format("%s[[%s|%s]]%s[[%s|%s]]%s[[%s|%s]]",
text, p_name, links[1], s, p_talk_name, links[2], s, p_edit_name, links[3])
.. "</span>"
.. "</span>"
end
end


-- Wrapper function for [[Template:Navbar]]
function p.navbar(frame)
local name = frame.args["name"]
local namespace = frame.args["namespace"]
local mode = frame.args["mode"]
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 frame:preprocess(result)
end
-- Navbox for lumatone mappings
function p.lumatone_map(frame)
function p.lumatone_map(frame)
local root_page_name = frame:preprocess("{{ROOTPAGENAME}}")
local debugg = yesno(frame.args["debug"])
local a = root_page_name: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
local out_str = frame:preprocess("{{Navbox"
local idxn1 = x - 1
.. "|name=Lumatone mapping navigation"
local idxn2 = x - 2
.. "|Title=[[Lumatone|Lumatone mappings]]"
local idxn3 = x - 3
.. "|Data 1=<div style=\"text-align: center;\"><div style=\"margin: auto auto auto auto;\">"
local idx1 = x + 1
.. ((x >= thresh + 4) and "'''&larr;''' " or "")
local idx2 = x + 2
.. ((x >= thresh + 3) and "[[Lumatone mapping for " .. (x - 3) .. "edo|" .. (x - 3) .. "edo]] &bull; " or "")
local idx3 = x + 3
.. ((x >= thresh + 2) and "[[Lumatone mapping for " .. (x - 2) .. "edo|" .. (x - 2) .. "edo]] &bull; " or "")
.. ((x >= thresh + 1) and "[[Lumatone mapping for " .. (x - 1) .. "edo|" .. (x - 1) .. "edo]] &bull; " or "")
local result = "<br />{{Navbox\n"
.. "'''Lumatone mapping for " .. x .. "edo''' &bull; "
.. "| name = Navbox Lumatone\n"
.. "[[Lumatone mapping for " .. (x + 1) .. "edo|" .. (x + 1) .. "edo]] &bull; "
.. "| Title = [[Lumatone|Lumatone mappings]]\n"
.. "[[Lumatone mapping for " .. (x + 2) .. "edo|" .. (x + 2) .. "edo]] &bull; "
.. "| Data 1 = {{centre|"
.. "[[Lumatone mapping for " .. (x + 3) .. "edo|" .. (x + 3) .. "edo]] '''&rarr;'''</div></div>}}")
if x >= thresh + 4 then
result = result .. "'''&larr;''' "
end
if x >= thresh + 3 then
result = result .. string.format("[[Lumatone mapping for %sedo|%sedo]] &bull; ", idxn3, idxn3)
end
if x >= thresh + 2 then
result = result .. string.format("[[Lumatone mapping for %sedo|%sedo]] &bull; ", idxn2, idxn2)
end
if string.lower(root_page_name) ~= "lumatone mapping navigation" then
if x >= thresh + 1 then
out_str = out_str .. " [[Category:Lumatone mappings]] [[Category:" .. x .. "edo]]"
result = result .. string.format("[[Lumatone mapping for %sedo|%sedo]] &bull; ", idxn1, idxn1)
end
end
result = result
.. string.format("'''Lumatone mapping for %sedo''' &bull; ", x)
.. string.format("[[Lumatone mapping for %sedo|%sedo]] &bull; ", idx1, idx1)
.. string.format("[[Lumatone mapping for %sedo|%sedo]] &bull; ", idx2, idx2)
.. string.format("[[Lumatone mapping for %sedo|%sedo]] '''&rarr;'''}}\n", idx3, idx3)
.. "}}"


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


-- Navbox for fractional-octave temperaments
function p.frac_octave(frame)
function p.frac_octave(frame)
local root_page_name = frame:preprocess("{{ROOTPAGENAME}}")
local arpn = frame:preprocess("{{ARTICLEROOTPAGENAME}}")
local a = root_page_name:match("(%d+)%a+[%s%-]*[Oo]ctave%s*[Tt]emperament[s]?")
local debugg = yesno(frame.args["debug"])
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 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\n"
.. "| name = Navbox fractional-octave\n"
.. "| Title = [[Fractional-octave temperaments]]\n"
.. "| Data 1 = {{centre|"
if x >= thresh + 4 then
result = result .. "'''&larr;''' "
end
if x >= thresh + 3 then
result = result .. string.format("[[%s-octave temperaments|%s]] &bull; ", idxn4, idxn4)
end
if x >= thresh + 2 then
result = result .. string.format("[[%s-octave temperaments|%s]] &bull; ", idxn3, idxn3)
end
if x >= thresh + 1 then
result = result .. string.format("[[%s-octave temperaments|%s]] &bull; ", idxn2, idxn2)
end
if x >= thresh then
result = result .. string.format("[[%s-octave temperaments|%s]] &bull; ", idxn1, idxn1)
end
result = result
.. string.format("'''%s-octave''' &bull; ", ordinal(x))
.. string.format("[[%s-octave temperaments|%s]] &bull; ", idx1, idx1)
.. string.format("[[%s-octave temperaments|%s]] &bull; ", idx2, idx2)
.. string.format("[[%s-octave temperaments|%s]] &bull; ", idx3, idx3)
.. string.format("[[%s-octave temperaments|%s]] '''&rarr;'''}}\n", idx4, idx4)
.. "}}"
-- Debugger option
if debugg == true then
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>"
end
local out_str = frame:preprocess("<br />{{Navbox"
return frame:preprocess(result)
.. "|name=Navbox fractional-octave"
.. "|Title=[[Fractional-octave temperaments]]"
.. "|Data 1=<div style=\"text-align: center;\"><div style=\"margin: auto auto auto auto;\">"
.. ((x >= 5) and "'''&larr;''' " or "")
.. ((x >= 4) and "[[" .. ordinal(x - 3) .. "-octave temperaments|" .. ordinal(x - 3) .. "]] &bull; " or "")
.. ((x >= 3) and "[[" .. ordinal(x - 2) .. "-octave temperaments|" .. ordinal(x - 2) .. "]] &bull; " or "")
.. ((x >= 2) and "[[" .. ordinal(x - 1) .. "-octave temperaments|" .. ordinal(x - 1) .. "]] &bull; " or "")
.. "'''" .. ordinal(x) .. "-octave''' &bull; "
.. "[[" .. ordinal(x + 1) .. "-octave temperaments|" .. ordinal(x + 1) .. "]] &bull; "
.. "[[" .. ordinal(x + 2) .. "-octave temperaments|" .. ordinal(x + 2) .. "]] &bull; "
.. "[[" .. ordinal(x + 3) .. "-octave temperaments|" .. ordinal(x + 3) .. "]] '''&rarr;'''</div></div>}}")
return out_str
end
end


return p
return p

Latest revision as of 12:55, 1 June 2025

Module documentation[view] [edit] [history] [purge]

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 p = {}

local ordinal = require("Module:Ordinal")._ordinal
local yesno = require("Module:Yesno")

-- Main function called by navigation box templates
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 = " &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;\">"
		.. string.format("%s[[%s|%s]]%s[[%s|%s]]%s[[%s|%s]]",
			text, p_name, links[1], s, p_talk_name, links[2], s, p_edit_name, links[3])
		.. "</span>"
end

-- Wrapper function for [[Template:Navbar]]
function p.navbar(frame)
	local name = frame.args["name"]
	local namespace = frame.args["namespace"]
	local mode = frame.args["mode"]
	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 frame:preprocess(result)
end

-- Navbox for lumatone mappings
function p.lumatone_map(frame)
	local debugg = yesno(frame.args["debug"])
	local x = tonumber(frame.args["edo"]:match("(%d+)"))
	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\n"
		.. "| name = Navbox Lumatone\n"
		.. "| Title = [[Lumatone|Lumatone mappings]]\n"
		.. "| Data 1 = {{centre|"
	
	if x >= thresh + 4 then
		result = result .. "'''&larr;''' "
	end
	
	if x >= thresh + 3 then
		result = result .. string.format("[[Lumatone mapping for %sedo|%sedo]] &bull; ", idxn3, idxn3)
	end
	
	if x >= thresh + 2 then
		result = result .. string.format("[[Lumatone mapping for %sedo|%sedo]] &bull; ", idxn2, idxn2)
	end
	
	if x >= thresh + 1 then
		result = result .. string.format("[[Lumatone mapping for %sedo|%sedo]] &bull; ", idxn1, idxn1)
	end
		
	result = result
		.. string.format("'''Lumatone mapping for %sedo''' &bull; ", x)
		.. string.format("[[Lumatone mapping for %sedo|%sedo]] &bull; ", idx1, idx1)
		.. string.format("[[Lumatone mapping for %sedo|%sedo]] &bull; ", idx2, idx2)
		.. string.format("[[Lumatone mapping for %sedo|%sedo]] '''&rarr;'''}}\n", idx3, idx3)
		.. "}}"

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

-- Navbox for fractional-octave temperaments
function p.frac_octave(frame)
	local arpn = frame:preprocess("{{ARTICLEROOTPAGENAME}}")
	local debugg = yesno(frame.args["debug"])
	local a = arpn:match("(%d+)%a+[%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\n"
		.. "| name = Navbox fractional-octave\n"
		.. "| Title = [[Fractional-octave temperaments]]\n"
		.. "| Data 1 = {{centre|"
	
	if x >= thresh + 4 then
		result = result .. "'''&larr;''' "
	end
	
	if x >= thresh + 3 then
		result = result .. string.format("[[%s-octave temperaments|%s]] &bull; ", idxn4, idxn4)
	end
	
	if x >= thresh + 2 then
		result = result .. string.format("[[%s-octave temperaments|%s]] &bull; ", idxn3, idxn3)
	end
	
	if x >= thresh + 1 then
		result = result .. string.format("[[%s-octave temperaments|%s]] &bull; ", idxn2, idxn2)
	end
	
	if x >= thresh then
		result = result .. string.format("[[%s-octave temperaments|%s]] &bull; ", idxn1, idxn1)
	end
	
	result = result
		.. string.format("'''%s-octave''' &bull; ", ordinal(x))
		.. string.format("[[%s-octave temperaments|%s]] &bull; ", idx1, idx1)
		.. string.format("[[%s-octave temperaments|%s]] &bull; ", idx2, idx2)
		.. string.format("[[%s-octave temperaments|%s]] &bull; ", idx3, idx3)
		.. string.format("[[%s-octave temperaments|%s]] '''&rarr;'''}}\n", idx4, idx4)
		.. "}}"

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

return p