-- This module implements Template:Bibleverse.local p =
--codes from bvf that may be in uselocal version_num_cds =
--possible book inputs, based on Chicago Manuallocal book_aliases =
local apoc =
--these books only have one chapter, have to be handled differentlylocal no_chaps =
--sets the website to be used for each version, biblegateway is the fallback so don't define any for itlocal site_tbl =
--pattern for the url of each site, use _book, v_range, etc. for variableslocal urlpat_tbl =
--changes book name to use in url for each site, only if necessarylocal site_book_tbl =
--changes to the version name to be used in urls, only if necessarylocal site_version_tbl =
local function trimArg(arg) if arg
' ' or arg
local function valueExists(tbl, value) for k,v in pairs(tbl) do if value
local function titlecase(arg) -- http://grammar.yourdictionary.com/capitalization/rules-for-capitalization-in-titles.html -- recommended by The U.S. Government Printing Office Style Manual: -- 'Capitalize all words in titles of publications and documents, -- except a, an, the, at, by, for, in, of, on, to, up, and, as, but, or, and nor.' local alwayslower = local res = local s = mw.text.trim(arg or ) local words = mw.text.split(s, '_') for i, s in ipairs(words) do s = string.lower(s) if i > 1 then if not alwayslower[s] then s = mw.getContentLanguage:ucfirst(s) end else s = mw.getContentLanguage:ucfirst(s) end words[i] = s end return table.concat(words, '_')end
function p.main(frame) local pframe = frame:getParent local args =
for i, v in ipairs(pframe.args) do args[i] = trimArg(v) end
local default_version = 'nrsv' local input_book = local ref = local version = local version_num local text = if args[1]
nil or tonumber(args[1]) ~= nil then -- first argument is a numeric prefix and second is book name input_book = trimArg((args[1] or ) .. ' ' .. (args[2] or )) or ref = args[3] or version = mw.ustring.lower(args[4] or default_version) text = args[5] or trimArg((input_book .. ' ' .. ref)) else -- first argument is the whole book name input_book = args[1] or ref = args[2] or version = mw.ustring.lower(args[3] or default_version) text = trimArg(args[4]) or (input_book .. ' ' .. ref) end if args.nobook
if tonumber(version) ~= nil then version = tonumber(version) version_num = true end
version = version_num_cds[version] or version
local errors = if version
'jp' then --chabad doesn't work so reroute table.insert(errors, '') version = default_version end
local book = mw.ustring.gsub(input_book, '%p', ) book = mw.ustring.gsub(book, ' ', '_') book = mw.ustring.lower(book)
local book_found = false for full_books, alias_tbls in pairs(book_aliases) do if mw.ustring.gsub(book, '_', )
local site = site_tbl[version] or 'biblegateway' --fall back on biblegateway for unrecognized version because it has so many versions if not book_found then site = 'bvf' end --when the book is not recognized, use bibleversefinder in case it is in that list of aliases if tonumber(version) ~= nil and version > 99 then site = 'bvf' end --remaining version codes used by bibleversefinder. 1-99 are biblegateway codes
if valueExists(apoc, book) and version
'oremus' then --oremus's nrsv doesn't have the apocrypha version = 'nrsvae' end --the anglicized version does
local urlpat = urlpat_tbl[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] local e_ref = mw.text.split(e_ref, '%p') for i, v in ipairs(s_ref) do s_ref[i] = mw.ustring.gsub(v, '%D', ) end --remove any non-numeric character (such as f) for i, v in ipairs(e_ref) do e_ref[i] = mw.ustring.gsub(v, '%D', ) end
local e_chap, e_vers, s_chap, s_vers if valueExists(no_chaps, book) then s_chap = 1 s_vers = s_ref[1] or s_ref[2] or 1 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 e_chap = e_ref[1] or s_chap e_vers = e_ref[2] or s_vers end
if type(site_book_tbl[site])
book = titlecase(book) --put book in title case, only because it looks better at oremus where they display the input
if site
'oremus') or (site
'bible_hub' then book = string.lower(book) elseif site
if type(site_version_tbl[site])
local v_range if s_ref[2]
local url = mw.ustring.gsub(urlpat, '_book', book) --get the components into the urls url = mw.ustring.gsub(url, 's_chap', s_chap) url = mw.ustring.gsub(url, 's_vers', s_vers) url = mw.ustring.gsub(url, 'e_chap', e_chap) url = mw.ustring.gsub(url, 'e_vers', e_vers) url = mw.ustring.gsub(url, 'v_range', v_range) url = mw.ustring.gsub(url, '_version', version)
local fulllink if site
if not book_found then table.insert(errors, '') end if version_num then table.insert(errors, '') end
return fulllink .. (table.concat(errors) or )end
return p