Module:Mormonverse Explained

local getArgs = require('Module:Arguments').getArgslocal p =

--possible book inputs--(spaces, caps, and punctuation are stripped beforehand)local book_aliases =

--these books only have one chapter, have to be handled differentlylocal no_chapters =

--pattern for the url of each site using _book etc.-- (underscore then letters [a-z]) for variableslocal url_path_tbl =

--changes book name to use in url for each site, only if necessarylocal site_book_tbl =

local function lookupTableReplace(arg, lookupTable) local abbrTitle = string.lower(arg) local fullTitle = arg for k, v in pairs(lookupTable) do if type(v)

"table" then for i = 1, #v do if v[i]

abbrTitle then fullTitle = k break --this is optional end end end end return fullTitleend

local function processBookName(arg) arg = arg:gsub('[-–— .]', ) -- removing dashes, spaces, periods arg = lookupTableReplace(arg, book_aliases) arg = arg:gsub("^%l", string.upper) -- capitalize first letter return argend

local function prepareURL(book, ref, site) local split_ref = mw.text.split(ref, '[-–—]') --split the ref into the part before and after the dash/hyphen local s_ref = mw.text.split(split_ref[1], '%p') --any punctuation can be used to separate chapter from verse local e_ref = split_ref[2] or split_ref[1] e_ref = mw.text.split(e_ref, '%p') for i, v in ipairs(s_ref) do s_ref[i] = v:gsub('%D', ) end --remove any non-numeric character (such as f) for i, v in ipairs(e_ref) do e_ref[i] = v:gsub('%D', ) end

local e_chap, e_vers, s_chap, s_vers local chapter_only = not s_ref[2] if no_chapters[book] then chapter_only = false s_chap = 1 s_vers = s_ref[2] or s_ref[1] or 1 --verse 3 can be specified as "3" or "1:3" e_chap = 1 e_vers = e_ref[2] or e_ref[1] or 1 else s_chap = s_ref[1] or 1 s_vers = s_ref[2] or 1 if e_ref[2] or not s_ref[2] then --chapter-chapter or chapter(:verse)?-chapter:verse e_chap = e_ref[1] or s_chap else --chapter:verse-verse e_chap = s_chap end e_vers = e_ref[2] or e_ref[1] or s_vers end

if site

'lds_org' then book = site_book_tbl[site][book] or book end

local v_range if e_chap

s_chap and e_vers

s_vers then v_range = s_vers else v_range = s_vers .. '-' .. e_vers end

local url_path = url_path_tbl[site] --get the components into the url local url = url_path:gsub('_%l+',) -- cut off verse details if (site

'lds_org' and chapter_only

true) then local tmp = mw.text.split(url, '&') url = tmp[1] end return urlend

local wikipedia_pages_verbatim =

local wikipedia_pages_other =

local function wikipediaLink(book) if (wikipedia_pages_verbatim[book]) then return '' .. book .. '' end if (wikipedia_pages_other[book]) then return '' .. book .. '' end return '' .. book .. ''end

local function refLinkText(ref) if (ref:match("^%a")) then -- if begins with letter return processBookName(ref) end return ref:gsub('[-–—]', ' - ')end

function p.main(frame) local args = getArgs(frame)

local book = args[1] local ref = args[2] local version = 'lds_org' -- args[3] or 'lds_org' book = processBookName(book) local url = prepareURL(book, ref, version)

return wikipediaLink(book) .. ' [' .. url .. ' ' .. refLinkText(ref) .. ']'end

return p