Module:Navbar

From Xenharmonic Wiki
Revision as of 07:31, 5 December 2024 by BudjarnLambeth (talk | contribs) (Add one more to the fractional octave box in either direction so that it can bridge the gap of 3 red links between the 37th and 41st octave pages (and probably other gaps that will emerge higher up in future as more pages are made))
Jump to navigation Jump to search
Module documentation[view] [edit] [history] [purge]
This module implements a metatemplate, and may be invoked by templates using its corresponding template Template:Navbar, or used directly from other modules.

This module is used by Template:Navbar to generate View/Talk/Edit links on templates.

To include this module in other modules, use local navbar = require("Module:Navbar")._navbar.


Introspection summary for Module:Navbar 
Functions provided (4)
Line Function Params
5 _navbar (main) (name, mode, text, namespace)
18 navbar (invokable) (frame)
27 lumatone_map (invokable) (frame)
54 frac_octave (invokable) (frame)
Lua modules required (1)
Variable Module Functions used
ordinal Module:Ordinal _ordinal

No function descriptions were provided. The Lua code may have further information.


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

local p = {}

function p._navbar(name, mode, text, namespace)
	mode = mode or ""
	text = (text == nil and "" or text .. " ")
	namespace = namespace or "Template"
	
	return "<span style=\"font-size: 0.8em;\">"
		.. text
		.. ((mode == "mini")
			and "[[" .. namespace .. ":" .. name .. "|V]] &bull; " .. "[[" .. namespace .. " talk:" .. name .. "|T]] &bull; " .. "[[Special:EditPage/" .. namespace .. ":" .. name .. "|E]]"
			or "[[" .. namespace .. ":" .. name .. "|View]] &bull; " .. "[[" .. namespace .. " talk:" .. name .. "|Talk]] &bull; " .. "[[Special:EditPage/" .. namespace .. ":" .. name .. "|Edit]]")
		.. "</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 root_page_name = frame:preprocess("{{ROOTPAGENAME}}")
	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"]) or tonumber(a)
	local thresh = 5
	
	local out_str = frame:preprocess("<br />{{Navbox"
		.. "|name=Navbox Lumatone"
		.. "|Title=[[Lumatone|Lumatone mappings]]"
		.. "|Data 1={{center|"
		.. ((x >= thresh + 4) and "'''&larr;''' " or "")
		.. ((x >= thresh + 3) and "[[Lumatone mapping for " .. (x - 3) .. "edo|" .. (x - 3) .. "edo]] &bull; " or "")
		.. ((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 "")
		.. "'''Lumatone mapping for " .. x .. "edo''' &bull; "
		.. "[[Lumatone mapping for " .. (x + 1) .. "edo|" .. (x + 1) .. "edo]] &bull; "
		.. "[[Lumatone mapping for " .. (x + 2) .. "edo|" .. (x + 2) .. "edo]] &bull; "
		.. "[[Lumatone mapping for " .. (x + 3) .. "edo|" .. (x + 3) .. "edo]] '''&rarr;'''</div></div>}}"
		.. "}}")
	
	if string.lower(root_page_name) ~= "lumatone mapping navigation" then
		out_str = out_str .. " [[Category:Lumatone mappings]] [[Category:" .. x .. "edo]]"
	end

	return out_str
end

function p.frac_octave(frame)
	local root_page_name = frame:preprocess("{{ROOTPAGENAME}}")
	local a = root_page_name:match("(%d+)%a+[%s%-]*[Oo]ctave%s*[Tt]emperament[s]?")
	local x = tonumber(frame.args["f"]) or tonumber(a)
	
	local out_str = frame:preprocess("<br />{{Navbox"
		.. "|name=Navbox fractional-octave"
		.. "|Title=[[Fractional-octave temperaments]]"
		.. "|Data 1={{center|"
		.. ((x >= 6) and "'''&larr;''' " or "")
		.. ((x >= 5) and "[[" .. ordinal(x - 4) .. "-octave temperaments|" .. ordinal(x - 4) .. "]] &bull; " 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) .. "]] &bull; "
		.. "[[" .. ordinal(x + 4) .. "-octave temperaments|" .. ordinal(x + 4) .. "]] '''&rarr;'''</div></div>}}"
		.. "}}")
	return out_str
end

return p