Content deleted Content added
m Remove completed TODO item and convert assert(false) statements into straight-up error calls |
m Protected "Module:LDSverse": request at RfPP ([Edit=Require autoconfirmed or confirmed access] (indefinite) [Move=Require autoconfirmed or confirmed access] (indefinite)) |
||
(4 intermediate revisions by one other user not shown) | |||
Line 3:
-- TODO:
-- Check the verse parameter to make sure it's a number (sometimes users
-- Take out the assert/error statements and handle errors more gracefully?▼
-- mistakenly include the en dash and ending verse number in this
-- parameter, e.g., {{LDS|Alma|alma|7|11–12}}). If it isn't a number,
-- default to citing to the chapter as a whole?
-- (As of September 2020, many have already been removed, so that's good.)
-- Functions with error statements left in them:
-- getFullBookName
-- handleOD
-- getStandardWork (only throws an error if pre-conditions not met)
-- getLectureOrdinal (only called with pcall)
--[[
Line 156 ⟶ 166:
local function getFullBookName(bookParam)
Returns the full name of a book of scripture based on the name/abbrev./alias provided
Pre-condition: bookParam is non-nil
NB: Because both Matthew in the NT and JST Matthew have just the title
"Matthew" on Wikisource, this function returns "JST Matthew" as the full name
Line 163 ⟶ 175:
]]
local function getFullBookName(bookParam)
for title,bookList in pairs(standardWorks) do
if bookList[bookParam] then
Line 207 ⟶ 218:
returns the Standard Work (as titled by Wikisource) that contains the book
passed in.
Preconditions: bookName is non-nil and was returned by getFullBookName
]]
local function getStandardWork(
-- check the standardWorks table for any values that have a key with the
-- full name of the book; if so, return the key (the title of the SW)
for title,bookList in pairs(standardWorks) do
if bookList[
end
error("Book <" ..
-- pre-conditions mean that this error should never occur, aka if it does,
-- something went very wrong!
end
Line 268 ⟶ 277:
-- Special case for handling the Official Declarations in the D&C
local function handleOD(displayTextParam, decNumber)
if
else -- decNumber wasn't 1 or 2 (and could even be nil)
if decNumber then
error("No such Official Declaration: " .. decNumber, 0)
else
error("No
end
end
end
-- for when the user has provided either no parameters or just one (the display
-- text for the wikilink)
local function handleFewParams(displayTextParam)
if not displayTextParam then
Line 336 ⟶ 352:
end
-- pre-condition: lectureNum is non-nil
local function getLectureOrdinal(lectureNum)
if lectureNum == "1" then return "First"
Line 391 ⟶ 408:
if fullBookName == "Lectures on Faith" then
if chapterParam then
if status then
fullBookName = "Lecture " .. ordinal
else
fullBookName = nil -- just cite to LoF generally
chapterParam = chapterParam .. " (invalid)" -- so user knows there was a problem
mw.log(ordinal) -- print error message to debug console (?)
end
else
fullBookName = nil -- The user has not provided a chapter (lecture) so this is treated as wanting to cite the LoF generally
Line 408 ⟶ 432:
wikiText = wikiText .. "]]" -- DON'T FORGET!!!
return wikiText
end
-- like the name says, this just counts the number of keys (aka indexes) in a table
local function countKeys(t)
local i = 0
for k,v in pairs(t) do i = i+1 end
return i
end
-- returns a (collapsed by default) wikitable listing all the aliases for every book
-- designed for use on the {{LDS}} template documentation page
function p.getBookAliasesWikiTable()
local wikiTable = [[{| class="wikitable sortable mw-collapsible mw-collapsed"
|+ class="nowrap" |LDS Template Book Name Aliases
! Standard Work !! Book !! Aliases
]]
for sw, bookList in pairs(standardWorks) do
wikiTable = wikiTable .. '|-\n|rowspan="' .. countKeys(bookList) .. '"|' .. sw .. "\n"
for book, aliases in pairs(bookList) do
wikiTable = wikiTable .. "| " .. book .. "\n| " .. table.concat(aliases, ", ") .. "\n|-\n"
end
end
wikiTable = wikiTable .. "|}"
return wikiTable
end
|