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)/_book#s_chap:s_vers" }

local urlpat = urlpat_tbl[site]

local input_book = trimArg( frame.args[1] ) local std_book = mw.ustring.lower(mw.ustring.gsub( input_book, " ", "_" )) local book_aliases = { ['gen'] = "genesis", ['exod'] = "exodus", ['lev'] = "leviticus", ['num'] = "numbers", ['deut'] = "deuteronomy", ['josh'] = "joshua", ['judg'] = "judges", ['ruth'] = "ruth", ['1sam'] = "1_samuel", ['2sam'] = "2_samuel", ['1chron'] = "1_chronicles", ['2chron'] = "2_chronicles", ['ezra'] = "ezra", ['neh'] = "nehemiah", ['esther'] = "esther", ['job'] = "job", ['ps'] = "psalms", ['prov'] = "proverbs", ['eccles'] = "ecclesiastes", ['songofsol'] = "songofsolomon", ['songofsongs'] = "songofsolomon", ['isa'] = "isaiah", ['jer'] = "jeremiah", ['lam'] = "lamentations", ['ezek'] = "ezekiel", ['dan'] = "daniel", ['hosea'] = "hosea", ['joel'] = "joel", ['amos'] = "amos", ['obad'] = "obadiah", ['jon'] = "jonah", ['mic'] = "micah", ['nah'] = "nahum", ['hab'] = "habakkuk", ['zeph'] = "zephaniah", ['hag'] = "haggai", ['zech'] = "zechariah", ['mal'] = "malachi", ['bar'] = "baruch", ['ecclus'] = "ecclesiasticus", ['ecclus'] = "sirach", ['ecclus'] = "sir", ['1esd'] = "1_esdras", ['2esd'] = "2_esdras", ['jth'] = "judith", ['1macc'] = "1_maccabees", ['2macc'] = "2_maccabees", ['profman'] = "prayer_of_manasses", ['profman'] = "prayer_of_manasseh", ['sus'] = "susanna", ['tob'] = "tobit", ['ws'] = "wisdom_of_solomon", ['wisdom'] = "wisdom_of_solomon", ['profaz'] = "prayer_of_azariah", ['matt'] = "matthew", ['mark'] = "mark", ['luke'] = "luke", ['john'] = "john", ['acts'] = "actsoftheapostles", ['rom'] = "romans", ['1cor'] = "1_corinthians", ['2corinthians'] = "2_corinthians", ['gal'] = "galatians", ['eph'] = "ephesians", ['phil'] = "philippians", ['col'] = "colossians", ['1thess'] = "1_thessalonians", ['2thess'] = "2_thessalonians", ['1tim'] = "1_timothy", ['2tim'] = "2_timothy", ['titus'] = "titus", ['philem'] = "philemon", ['heb'] = "hebrews", ['james'] = "james", ['1pet'] = "1_peter", ['2pet'] = "2_peter", ['1john'] = "1_john", ['2john'] = "1_john", ['3john'] = "1_john", ['jude'] = "jude", ['rev'] = "revelation", ['apocalypse'] = "revelation", } --	if valueExists( book_aliases, std_book ) then --		local book = std_book --	else local book = book_aliases[std_book] or std_book -- -- 	end site_book_tbl = { wikisource_kjv = { ['prayer_of_azariah'] = "Prayer of Azarias and Hymn of the Three Children" } 	}  local book = site_book_tbl[site][book] or book -- local string2 = require( "Module:String2" ) -- local book = string2( title, 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 input_book .. " " .. ref if site == "wikisource_kjv" then return "" .. text .. "" else return "[" .. url .. " " .. text .. "]" end end

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

function valueExists(tbl, value) for k,v in pairs(tbl) do   if value == v then return true end end return false end return p