Module:Numlinks: Difference between revisions
No edit summary |
No edit summary |
||
| Line 2: | Line 2: | ||
local ordinal = require("Module:Ordinal")._ordinal | local ordinal = require("Module:Ordinal")._ordinal | ||
local getArgs = require("Module:Arguments").getArgs | |||
local yesno = require("Module:yesno") | |||
local p = {} | local p = {} | ||
function p.side_numlinks( | function p.side_numlinks(args) | ||
local num_links = | local num_links = args["Link Count"] or 3 | ||
local curr_num = | local curr_num = args["Num 1"] or 2 | ||
local min_num = | local min_num = args["Min 1"] or 1 | ||
local page_text = | local page_text = args["Page Text"] or { "PRE-TEXT", "POST-TEXT" } | ||
local link_text = | local link_text = args["Link Text"] or nil | ||
local is_ordinal = | local is_ordinal = args["Is Ordinal 1"] ~= nil and args["Is Ordinal 1"] or false | ||
-- Preprocess page and link text | -- Preprocess page and link text | ||
| Line 58: | Line 60: | ||
end | end | ||
function p.eight_numlinks(curr_num_1 | function p.eight_numlinks(args) | ||
local curr_num_1 = args["Num 1"] or 2 | |||
local min_num_1 = args["Min 1"] or 1 | |||
local curr_num_2 = args["Num 2"] or 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 | |||
end | end | ||
| Line 68: | Line 78: | ||
-- - Page text: Text is formatted as [pre-text][n][post-text], stored in a table | -- - 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 | -- { pre } or { pre, post }. If the link config is for 8 links, then text is | ||
-- formatted as [pre-text][ | -- formatted as [pre-text][n1][mid-text][n2][post-text], stored in a table | ||
-- { mid, post } or { pre, mid, post }. Pre-text can be omitted since most | -- { mid, post } or { pre, mid, post }. Pre-text can be omitted since most | ||
-- pages don't have pre-text (12edo, 5L 2s). | -- pages don't have pre-text (12edo, 5L 2s). | ||
| Line 76: | Line 86: | ||
-- isn't a maximum since these numbers are assumed to be either natural or | -- isn't a maximum since these numbers are assumed to be either natural or | ||
-- whole numbers. | -- whole numbers. | ||
function p._numlinks( | function p._numlinks(frame) | ||
local | local args = getArgs(frame) | ||
args["Num 1"] = tonumber(args["Num 1"]) | |||
args["Min 1"] = tonumber(args["Min 1"]) or 1 | |||
args["Num 2"] = tonumber(args["Num 2"]) or nil | |||
args["Min 2"] = tonumber(args["Min 2"]) or nil | |||
-- Create numbered navigation links | -- Create numbered navigation links | ||
local navigation_links = {} | local navigation_links = {} | ||
if | if args["Num 2"] == nil then | ||
navigation_links = p.side_numlinks( | navigation_links = p.side_numlinks(args) | ||
else | |||
navigation_links = p.eight_numlinks(args) | |||
end | end | ||