Module:Numlinks: Difference between revisions

Ganaram inukshuk (talk | contribs)
todo; revert previous changes for clarity
Ganaram inukshuk (talk | contribs)
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 1"]
local curr_num  = args["Num"]
local min_num    = args["Min 1"] or 1
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 1"] ~= nil and args["Is Ordinal 1"] or false
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.numlinks_2d(args)
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)
-- Generate a table of previous and next links for numbered pages, with support
-- for up to two numbers. Args are as follows:
-- - 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][n1][mid-text][n2][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(frame)
function p._numlinks(frame)
local args = getArgs(frame)
local args = getArgs(frame)
args["Num 1"] = tonumber(args["Num 1"])
args["Num"] = tonumber(args["Num"])
args["Min 1"] = tonumber(args["Min 1"]) or 1
args["Min"] = tonumber(args["Min"]) or 1
args["Num 2"] = tonumber(args["Num 2"]) or nil
args["Link Count"] = tonumber(args["Link Count"]) or 1
args["Min 2"] = tonumber(args["Min 2"]) or nil
-- Create numbered navigation links
-- Create numbered navigation links
local navigation_links = {}
local navigation_links = p.numlinks(args)
if args["Num 2"] == nil then
navigation_links = p.numlinks_1_val(args)
else
navigation_links = p.numlinks_2_val(args)
end


return navigation_links
return navigation_links
Line 123: Line 103:


function p.tester()
function p.tester()
return p.side_numlinks()
return p._numlinks()
end
end


return p
return p