Module:Prime limit navigation: Difference between revisions

From Xenharmonic Wiki
Jump to navigation Jump to search
ArrowHead294 (talk | contribs)
m 75% seems a little too small
ArrowHead294 (talk | contribs)
m Fix typo
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}


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}
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)
local function table_index(t, v)
for i, ti in ipairs (t) do
for i, ti in ipairs (t) do
if v == ti then
if v == ti then
Line 15: Line 16:
local i = table_index(PRIME_LIST, tonumber (frame.args['limit']))
local i = table_index(PRIME_LIST, tonumber (frame.args['limit']))
local entry_prev, entry_curr, entry_next, out_elem = "", "", "", ""
local entry_prev, entry_curr, entry_next, out_elem = "", "", "", ""
if PRIME_LIST[i] then
if PRIME_LIST[i] then
entry_curr = "[[" .. PRIME_LIST[i] .. "-limit]]"
entry_curr = string.format("[[%d-limit]]"PRIME_LIST[i])
if PRIME_LIST[i - 1] then
if PRIME_LIST[i - 1] then
entry_prev = "<span style=\"font-size: 0.8em;\">[[" .. PRIME_LIST[i-1] .. "-limit|&larr; " .. PRIME_LIST[i-1] .. "-limit]]</span> "
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
else
entry_prev = ""
entry_prev = ""
end
end
if PRIME_LIST[ i+ 1] then
if PRIME_LIST[i + 1] then
entry_next = " <span style=\"font-size: 0.8em;\">[[" .. PRIME_LIST[i+1] .. "-limit|" .. PRIME_LIST[i+1] .. "-limit &rarr;]]</span>"
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
else
entry_next = ""
entry_next = ""
Line 29: Line 35:
end
end
out_elem = "<div class=\"toccolours\" style=\"float: right; text-align: center;\">\n" ..
local result = "<div class=\"toccolours\" style=\"float: right; margin: 0px 0px 4px 4px;\">\n"
"<div style=\"margin: auto auto auto auto;\">'''[[Prime limit]]'''</div>\n" ..
.. "{{centre|'''[[Prime limit]]'''}}\n"
"<hr />\n" ..
.. "<hr />\n"
entry_prev .. entry_curr .. entry_next .. "\n" ..
.. string.format("%s%s%s\n", entry_prev, entry_curr, entry_next)
"</div>"
.. "</div>"
if yesno(frame.args["debug"]) == true then
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>"
end
return out_elem
return frame:preprocess(result)
end
end


return p;
return p

Latest revision as of 13:11, 1 June 2025

Module documentation[view] [edit] [history] [purge]
Note: Do not invoke this module directly; use the corresponding template instead: Template:Prime limit navigation.

This module generates the navigation bar for prime limit pages.


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, out_elem = "", "", "", ""
	
	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"
		.. "<hr />\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