-- This module implements Template:Bibleverse.local p =
--codes from bvf that may be in uselocal version_num_codes =
--possible book inputs, based on Chicago Manuallocal book_aliases =
local apoc =
--these books only have one chapter, have to be handled differentlylocal no_chapters =
--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 using _book etc. (underscore then letters [a-z]) 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(text) if type(text)
local function valueExists(tbl, value) for _, 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 words = mw.text.split(mw.text.trim(arg or ), '_') 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 targs = frame:getParent.args local args = for _, param in ipairs do args[param] = trimArg(targs[param]) end local default_version = 'nrsv' local input_book = local ref = local version = local version_num local text = local wikilink = local mainspace = mw.title.getCurrentTitle:inNamespaces(0) 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 wikilink = trimArg((args[1] or 'Book of') .. ' ' .. (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 wikilink = 'Book of ' .. args[1] ref = args[2] or version = mw.ustring.lower(args[3] or default_version) text = args[4] or (input_book .. ' ' .. ref) end if args.nobook
'yes' then text = ref wikilink = '' .. input_book .. ' ' else wikilink = end if args.multi
if tonumber(version) then version = version_num_codes[tonumber(version)] or version version_num = true end
local errors = if version
'jp' then --chabad doesn't work so reroute version = 'he' if mainspace then table.insert(errors, '') end end
local book = input_book:gsub('%p', ):gsub(' ', '_') book = mw.ustring.lower(book)
local book_found = false local standard = book:gsub('_', ) for full_book, aliases in pairs(book_aliases) do if standard
local site = site_tbl[version] or 'biblegateway' --fall back on biblegateway for unrecognized version because it has so many versions
if apoc[book] and version
'oremus' then --oremus's nrsv doesn't have the apocrypha version = 'nrsvae' --the anglicized version does end
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] 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 type(site_book_tbl[site])
book = titlecase(book) --title case looks better at oremus where they display the input
if site
'biblica' or site
'esv_bible' or site
'bible_hub' then book = string.lower(book) elseif site
'table' then version = site_version_tbl[site][version] end
local v_range if chapter_only then if e_chap
s_chap and e_vers
s_chap then v_range = s_chap .. ':' .. s_vers .. '–' .. e_vers else v_range = s_chap .. ':' .. s_vers .. '–' .. e_chap .. ':' .. e_vers end end
local url = urlpat:gsub('_%l+',)
local fulllink if site
if mainspace then if not book_found then table.insert(errors, '
Template:Bibleverse with invalid book') end if version_num then table.insert(errors, '') end end return fulllink .. table.concat(errors)endreturn p