Module:Prime limit navigation

From Xenharmonic Wiki
Revision as of 15:11, 23 September 2025 by FloraC (talk | contribs) (+ odd limit navigation)
Jump to navigation Jump to search
Module documentation[view] [edit] [history] [purge]
This module should not be invoked directly; use its corresponding templates instead: Template:Prime limit navigation and Template:Odd limit navigation.


This module generates the navigation bars for prime limit and odd limit pages.

Introspection summary for Module:Prime limit navigation 
Functions provided (2)
Line Function Params
15 prime_limit_navigation (invokable) (frame)
50 odd_limit_navigation (invokable) (frame)
Lua modules required (1)
Variable Module Functions used
yesno Module:Yesno yesno

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


local p = {}

local yesno = require("Module:Yesno")
local PRIME_LIST = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127}

local function table_index(t, v)
	for i, ti in ipairs (t) do
		if v == ti then
			return i
		end
	end
	return nil
end

function p.prime_limit_navigation(frame)
	local i = table_index(PRIME_LIST, tonumber (frame.args['limit']))
	local entry_prev, entry_curr, entry_next = "", "", ""
	
	if PRIME_LIST[i] then
		entry_curr = string.format("[[%d-limit]]",  PRIME_LIST[i])
		if PRIME_LIST[i - 1] then
			entry_prev = string.format("<span style=\"font-size: 0.8em;\">"
				.. "[[%d-limit|'''&larr;'''&nbsp;%d-limit]]"
				.. "</span>&nbsp;&nbsp;", PRIME_LIST[i - 1], PRIME_LIST[i - 1])
		else
			entry_prev = ""
		end
		if PRIME_LIST[i + 1] then
			entry_next = string.format("&nbsp;&nbsp;<span style=\"font-size: 0.8em;\">"
				.. "[[%d-limit|%d-limit&nbsp;'''&rarr;''']]"
				.. "</span>", PRIME_LIST[i + 1], PRIME_LIST[i + 1])
		else
			entry_next = ""
		end
	end
	
	local result = "<div class=\"toccolours\" style=\"float: right; margin: 0px 0px 4px 4px;\">\n"
		.. "{{centre|'''[[Prime limit]]'''}}\n"
		.. "----\n"
		.. string.format("%s%s%s\n", entry_prev, entry_curr, entry_next)
		.. "</div>"
	
	if yesno(frame.args["debug"]) == true then
		result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>"
	end
	
	return frame:preprocess(result)
end

function p.odd_limit_navigation(frame)
	local limit = frame.args['limit']
	local entry_prev, entry_curr, entry_next = "", "", "", ""
	
	if limit > 0 and limit % 2 == 1 then
		entry_curr = string.format("[[%d-odd-limit]]", limit)
		limit_prev = limit - 2
		if limit_prev > 0 then
			entry_prev = string.format("<span style=\"font-size: 0.8em;\">"
				.. "[[%d-odd-limit|'''&larr;'''&nbsp;%d-odd-limit]]"
				.. "</span>&nbsp;&nbsp;", limit_prev, limit_prev)
		else
			entry_prev = ""
		end
		limit_next = limit + 2
		if limit_next > 0 then
			entry_next = string.format("&nbsp;&nbsp;<span style=\"font-size: 0.8em;\">"
				.. "[[%d-odd-limit|%d-odd-limit&nbsp;'''&rarr;''']]"
				.. "</span>", limit_next, limit_next)
		else
			entry_next = ""
		end
	end
	
	local result = "<div class=\"toccolours\" style=\"float: right; margin: 0px 0px 4px 4px;\">\n"
		.. "{{centre|'''[[Odd limit]]'''}}\n"
		.. "----\n"
		.. string.format("%s%s%s\n", entry_prev, entry_curr, entry_next)
		.. "</div>"
	
	if yesno(frame.args["debug"]) == true then
		result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>"
	end
	
	return frame:preprocess(result)
end

return p