Module:LDSverse: Difference between revisions

Content deleted Content added
Remove periods in book abbreviations
m Protected "Module:LDSverse": request at RfPP ([Edit=Require autoconfirmed or confirmed access] (indefinite) [Move=Require autoconfirmed or confirmed access] (indefinite))
 
(5 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 statements and handle errors more gracefully?
-- mistakenly include the en dash and ending verse number in this
-- Handle situations where the book name parameter is mistakenly left out (e.g., {{LDS|Alma|7|11}}): if the "bookParam" evaluates to a number, shift all the parameters "down" one (i.e., bookParam->chapterParam, chapterParam->verseParam, etc.) and treat the display text (minus any period or other punctuation) is the bookParam.
-- parameter, e.g., {{LDS|Alma|alma|7|11–12}}). If it isn't a number,
-- default to citing to the chapter as a whole?
-- Take out the assertremaining error statements and handle errors more gracefully?.
-- (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 157 ⟶ 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 164 ⟶ 175:
]]
local function getFullBookName(bookParam)
 
assert(bookParam, "No book name provided")
for title,bookList in pairs(standardWorks) do
if bookList[bookParam] then
Line 200 ⟶ 210:
-- At this point we've searched, without regard to case, creed, or color,
-- for the alleged book of scripture they provided, but it ain't here!
asserterror(false, "Book <" .. bookParam .. "> not found in Standard Works", 0)
return ""
end --function getFullBookName(bookParam)
Line 208 ⟶ 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(bookParambookName)
assert(bookParam, "No book name provided")
local book = getFullBookName(bookParam)
assert(book, "Book <" .. bookParam .. "> not found in Standard Works")
-- 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[bookbookName] then return title end
end
asserterror(false, "Book <" .. bookbookName .. "> is not a full book name found in Standard Works", 0)
-- pre-conditions mean that this error should never occur, aka if it does,
-- something went very wrong!
end
 
Line 269 ⟶ 277:
 
-- Special case for handling the Official Declarations in the D&C
local-- functionPre-condition: handleOD(displayTextParam, chapter)is non-nil
local function handleOD(displayTextParam, decNumber)
if chapterdecNumber == "1" then
return wsBaseURL .. "The_Doctrine_and_Covenants/Official_Declaration_1|" .. displayTextParam .. " 1]]"
elseif chapterdecNumber == "2" then
return "[https://www.churchofjesuschrist.org/study/scriptures/dc-testament/od/2?lang=eng " .. displayTextParam .. " 2]"
else -- decNumber wasn't 1 or 2 (and could even be nil)
if decNumber then
asserterror(false, "No such Official Declaration: " .. chapterdecNumber, 0)
else
error("No official declaration number provided", 0)
assert(false, "No such Official Declaration: " .. chapter)
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 337 ⟶ 352:
end
 
-- pre-condition: lectureNum is non-nil
local function getLectureOrdinal(lectureNum)
if lectureNum == "1" then return "First"
Line 347 ⟶ 363:
end
asserterror(false, "Lecture on Faith number <" .. lectureNum .. "> does not exist (should be between 1 and 7)", 0)
end
 
Line 392 ⟶ 408:
if fullBookName == "Lectures on Faith" then
if chapterParam then
fullBookNamelocal =status, "Lectureordinal "= .. getLectureOrdinalpcall(getLectureOrdinal, chapterParam)
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 409 ⟶ 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