Module:Numlinks: Difference between revisions
Jump to navigation
Jump to search
todo; revert previous changes for clarity |
some cleanup |
||
| Line 12: | Line 12: | ||
function p.numlinks(args) | function p.numlinks(args) | ||
local num_links = args["Link Count"] | local num_links = args["Link Count"] | ||
local curr_num = args["Num | local curr_num = args["Num"] | ||
local min_num = args["Min | local min_num = args["Min"] or 1 | ||
local page_text = args["Page Text"] or { "PRE-TEXT", "POST-TEXT" } | local page_text = args["Page Text"] or { "PRE-TEXT", "POST-TEXT" } | ||
local link_text = args["Link Text"] or nil | local link_text = args["Link Text"] or nil | ||
local is_ordinal = args["Is Ordinal | local is_ordinal = args["Is Ordinal"] ~= nil and args["Is Ordinal"] or false | ||
-- Preprocess page and link text | -- Preprocess page and link text | ||
| Line 63: | Line 63: | ||
end | end | ||
-- wip | -- wip; to be placed in its own module | ||
function p. | function p.numlinks_2num(args) | ||
local curr_num_1 = args["Num 1"] | local curr_num_1 = args["Num 1"] | ||
local min_num_1 = args["Min 1"] or 1 | local min_num_1 = args["Min 1"] or 1 | ||
| Line 89: | Line 89: | ||
-- Main function (TODO: split functionality into two modules) | -- Main function (TODO: split functionality into two modules) | ||
function p._numlinks(frame) | function p._numlinks(frame) | ||
local args = getArgs(frame) | local args = getArgs(frame) | ||
args["Num | args["Num"] = tonumber(args["Num"]) | ||
args["Min | args["Min"] = tonumber(args["Min"]) or 1 | ||
args[" | args["Link Count"] = tonumber(args["Link Count"]) or 1 | ||
-- Create numbered navigation links | -- Create numbered navigation links | ||
local | local navigation_links = p.numlinks(args) | ||
return navigation_links | return navigation_links | ||
| Line 123: | Line 103: | ||
function p.tester() | function p.tester() | ||
return p. | return p._numlinks() | ||
end | end | ||
return p | return p | ||
Revision as of 08:43, 8 October 2025
- 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 p = {}
local getArgs = require("Module:Arguments").getArgs
local ordinal = require("Module:Ordinal")._ordinal
local yesno = require("Module:Yesno")
-- TODO:
-- - Split into two modules: Numlinks and Numlinks-2D, since behaviors are too
-- dissimilar to keep within one module
function p.numlinks(args)
local num_links = args["Link Count"]
local curr_num = args["Num"]
local min_num = args["Min"] or 1
local page_text = args["Page Text"] or { "PRE-TEXT", "POST-TEXT" }
local link_text = args["Link Text"] or nil
local is_ordinal = args["Is Ordinal"] ~= nil and args["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
-- wip; to be placed in its own module
function p.numlinks_2num(args)
local curr_num_1 = args["Num 1"]
local min_num_1 = args["Min 1"] or 1
local curr_num_2 = args["Num 2"]
local min_num_2 = args["Min 2"] or 1
local page_text = args["Page Text"] or { "PRE-TEXT", "MID-TEXT", "POST-TEXT" }
local link_text = args["Link Text"] or nil
local is_ordinal_1 = args["Is Ordinal 1"] ~= nil and args["Is Ordinal 1"] or false
local is_ordinal_2 = args["Is Ordinal 1"] ~= nil and args["Is Ordinal 2"] or false
local x = curr_num_1
local y = curr_num_2
local link_nums = {
{x-1, y-1}, {x , y-1}, {x+1, y-1},
{x-1, y }, {x+1, y },
{x-1, y+1}, {x , y+1}, {x+1, y+1}
}
local links = {}
for i = 1, #link_nums do
end
end
-- Main function (TODO: split functionality into two modules)
function p._numlinks(frame)
local args = getArgs(frame)
args["Num"] = tonumber(args["Num"])
args["Min"] = tonumber(args["Min"]) or 1
args["Link Count"] = tonumber(args["Link Count"]) or 1
-- Create numbered navigation links
local navigation_links = p.numlinks(args)
return navigation_links
end
function p.tester()
return p._numlinks()
end
return p