Module:Numlinks
- This module implements a metatemplate, and may be invoked by templates using its corresponding template Template:Numlinks, or used directly from other modules.
This module generates previous and next links for a numbered page.
| Introspection summary for Module:Numlinks | |||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
| ||||||||||||||||||
No function descriptions were provided. The Lua code may have further information.
-- Page is following provisonal style guide: User:Ganaram_inukshuk/Provisional_style_guide_for_Lua
local ordinal = require("Module:Ordinal")._ordinal
local p = {}
function p.side_numlinks(num_links, curr_num, min_num, page_text, link_text, is_ordinal)
local num_links = num_links or 1
local curr_num = curr_num
local min_1 = min_1 or 1
local page_text = page_text or { "PRE-TEXT", "POST-TEXT" }
local link_text = link_text or nil
local is_ordinal = is_ordinal ~= nil and is_ordinal or false
-- Preprocess page and link text
if #page_text == 1 then
page_text = { "", page_text[1] }
end
if link_text ~= nil then
if #link_text == 1 then
link_text = { "", link_text[1] }
end
end
-- Produce next links
local next_links = ""
for i = 1, num_links do
local link = ""
local num = is_ordinal and ordinal(curr_num + i) or string.format("%s", curr_num + i)
if link_text == nil then
-- Link text is the same as the page text
link = string.format("[[%s%s%s]]", page_text[1], num, page_text[2])
else
-- Link and page text are different
link = string.format("[[%s%s%s|%s%s%s]]", page_text[1], num, page_text[2], link_text[1], num, link_text[2])
end
next_links = next_links .. link .. (i == num_links and "" or " ")
end
-- Produce prev links
local prev_links = ""
for i = 1, num_links do
local link = ""
local num = is_ordinal and ordinal(curr_num - i) or string.format("%s", curr_num - i)
if curr_num - i >= min_num then
if link_text == nil then
-- Link text is the same as the page text
link = string.format("[[%s%s%s]]", page_text[1], num, page_text[2])
else
-- Link and page text are different
link = string.format("[[%s%s%s|%s%s%s]]", page_text[1], num, page_text[2], link_text[1], num, link_text[2])
end
prev_links = (curr_num - i <= min_num and "" or " ") .. link .. prev_links
end
end
return { prev_links, next_links }
end
function p.eight_numlinks(curr_num, min_num, page_text, link_text)
end
-- Generate a table of previous and next links for numbered pages, with support
-- for up to two numbers. Args are as follows:
-- - Link config: what is the arrangement of links? Options are:
-- -- Side-1: For n, links are for n-1 and n+1
-- -- Side-2: For n, links are for n-2 to n+1
-- -- Side-3: For n, links are for n-3 to n+3
-- -- Side-4: For n, links are for n-4 to n+4
-- -- Side-5: For n, links are for n-5 to n+5
-- -- 8-Link: For n and m, links are n +/- 1 and m +/- 1. There are no options
-- for additional links.
-- - Is ordinal: should the values be cardinal numbers (eg, 12edo) or ordinal
-- numbers (eg, 12th-octave)?
-- - Page text: Text is formatted as [pre-text][n][post-text], stored in a table
-- { pre } or { pre, post }. If the link config is for 8 links, then text is
-- formatted as [pre-text][n][mid-text][m][post-text], stored in a table
-- { mid, post } or { pre, mid, post }. Pre-text can be omitted since most
-- pages don't have pre-text (12edo, 5L 2s).
-- - Link text: Same as page text, except this changes the text of the link. If
-- this is not specified, then the page and link text are the same.
-- - Min: The smallest allowed value for a numbered link. Default is 1. There
-- isn't a maximum since these numbers are assumed to be either natural or
-- whole numbers.
function p._numlinks(args)
local link_config = args["Link Config"]
local is_ordinal = args["Is Ordinal"] ~= nil and args["Is Ordinal"] or false
local page_text = args["Page Text"]
local link_text = args["Link Text"]
local min_num = args["Min Num"] ~= nil and args["Min Num"] or 1
local curr_num_1 = args["Current Num 1"]
local curr_num_2 = args["Current Num 2"]
-- Parse link config
local num_links = 0
local is_side = false
local is_eight = false
if link_config == "Side-1" then
-- One set of prev/next links
local num_links = 1
local is_side = true
elseif link_config == "Side-2" then
-- Two sets of prev/next links
local num_links = 2
local is_side = true
elseif link_config == "Side-3" then
-- Three sets of prev/next links
local num_links = 3
local is_side = true
elseif link_config == "Side-4" then
-- Four sets of prev/next links
local num_links = 4
local is_side = true
elseif link_config == "Side-5" then
-- Five sets of prev/next links
local num_links = 5
local is_side = true
elseif link_config == "8-Link" then
-- Prev/next links for two changing values
local is_eight = true
else
-- One set of prev/next links as the default
local num_links = 1
local is_side = true
end
-- Create numbered navigation links
local navigation_links = {}
if is_side then
navigation_links = p.side_numlinks(num_links, curr_num, min_num, page_text, link_text, is_ordinal)
end
return navigation_links
end
return p