Module:BibleQuote

From Seeds of the Word, the encyclopedia of the influence of the Gospel on culture
Revision as of 17:56, September 24, 2020 by Johnrdorazio (talk | contribs)

Documentation for this module may be created at Module:BibleQuote/doc

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

local VERSIONS_AVAILABLE = {
	"NABRE",
	"NVBSE",
	"LUZZI",
	"CEI2008",
	"DRB",
	"VGCL"
}

-- let's keep the needle in a haystack ordering typical of PHP
local function in_table (val, tab)
    for index, value in ipairs(tab) do
        if value == val then
            return true
        end
    end
    return false
end

local p = {} --p stands for package

function p.isValidVersion( frame )
    local args = getArgs(frame, {
    	--we will only consider arguments that are passed by the template itself in the invoke
    	frameOnly = true
    })
    -- let's make sure defaults are set
    args.version = args.version or "NABRE"
    -- also make sure it's not empty
    if args.version == "" then
    	args.version = "NABRE"
    end
	if (in_table(args.version, VERSIONS_AVAILABLE)) then
		return 1
	else
		return 0
	end
end

function p.main( frame )
    local args = getArgs(frame, {
    	--we will only consider arguments that are passed by the template itself in the invoke
    	frameOnly = true
    })
    -- let's make sure defaults are set
    args.version = args.version or "NABRE"
    if args.version == "" then
    	args.version = "NABRE"
    end
    args.ref = args.ref or "John 3:16"
    if args.ref == "" then
    	args.ref = "John 3:16"
    end
    args.inline = args.inline or "true"
    if args.inline == "" or args.inline == 1 or args.inline == "true" then
    	args.inline = "true"
    elseif args.inline == 0 or args.inline == "false" then
    	args.inline = "false"
    end
    return p._main(args)
end

function p._main( args )
	if (in_table(args.version, VERSIONS_AVAILABLE)) then
		if args.inline == "true" then
			return "<span class=\"bibleQuoteRef\" data-ref=\"" .. args.ref .. "\" data-version=\"" .. args.version .. "\" data-inline=\"" .. args.inline .. "\">" .. args.ref .. "</span>"
		else
			return "<div class=\"bibleQuoteRef\" data-ref=\"" .. args.ref .. "\" data-version=\"" .. args.version .. "\" data-inline=\"" .. args.inline .. "\"></div>"
		end
	else
		return "<span class=\"bibleQuoteRefBroken\" data-ref=\"" .. args.ref .. "\" data-version=\"" .. args.version .. "\" data-inline=\"" .. args.inline .. "\" title=\"The Bible version '" .. args.version .. "' is not supported by the BibleGet endpoint.\">" .. args.ref .. "</span><sup class=\"bibleQuoteRefBrokenReason\" title=\"The Bible version '" .. args.version .. "' is not supported by the BibleGet endpoint.\">[!]</sup>"
	end
end
--[[
function p.cacheDirExists( args )
	if(fs.is_dir("/var/log/snort") = nil) then
		
	else
			
	end
end
]]
return p