Module:Bibleverse

local p = {}

function p.main( frame ) local defver   = "nrsv" local version = trimArg( frame.args[3] ) or defver site_tbl = { nrsv = "oremus", kjv = "wikisource_kjv" } local site    = site_tbl[version] urlpat_tbl = { oremus = "http://bible.oremus.org/?passage=_book+s_chap:s_vers-e_chap:e_vers&version=_version", wikisource_kjv = "s:Bible(King James)/s_chap#s_vers" }

local urlpat = urlpat_tbl[site]

local book = trimArg( frame.args[1] ) book_aliases = { gen = "genesis" } local book = book_aliases[book] or book local ref       = trimArg( frame.args[2] ) local split_ref   = mw.text.split( ref, "[-–—]") local s_ref       = mw.text.split( split_ref[1], "%p") local s_chap      = s_ref[1] local s_vers      = s_ref[2] local e_ref       = split_ref[2] or split_ref[1] local e_ref       = mw.text.split( e_ref, "%p") local e_chap       = e_ref[1] local e_vers       = e_ref[2] local url_w_bk = mw.ustring.gsub( urlpat, "_book", book ) local url_w_s_chap = mw.ustring.gsub( url_w_bk, "s_chap", s_chap ) local url_w_s_vers = mw.ustring.gsub( url_w_s_chap, "s_vers", s_vers ) local url_w_e_chap = mw.ustring.gsub( url_w_s_vers, "e_chap", e_chap ) local url_w_e_vers = mw.ustring.gsub( url_w_e_chap, "e_vers", e_vers ) local url_w_version = mw.ustring.gsub( url_w_e_vers, "_version", version ) local url = url_w_version local text = trimArg( frame.args[4] ) or book .. " " .. ref if site == "wikisource" then return "" .. text .. "" else return "[" .. url .. " " .. text .. "]" end end

function trimArg(arg)

if arg == "" or arg == nil then return nil else return mw.text.trim(arg) end

end

return p