Module:BibleQuote
Documentation for this module may be created at Module:BibleQuote/doc
local p = {} --p stands for package
local getArgs = require('Module:Arguments').getArgs
local function verseNamespace()
return "VerseTemplate"
end
local function removePilcrow(verse)
return (string.gsub(verse, "^<span class=\"pilcrow\">¶</span>%s*", ""))
end
local function addSingleSpace(verse)
return (string.gsub(verse, "^", "<br>"))
end
local function addDoubleSpace(verse)
return (string.gsub(verse, "^", "<br><br>"))
end
local function addIndent(verse)
return (string.gsub(verse, "^", " "))
end
local function compose(...)
local chain = { ... }
local function recurse(i, ...)
if i == #chain then return chain[i](...) end
return recurse(i + 1, chain[i](...))
end
return function(...) return recurse(1, ...) end
end
local function renderVerses(verseSpec, showVerseNumber, showPilcrow, singleSpace, doubleSpace, indent)
local book, chapter, startVerse, stopVerse
if string.find(verseSpec, "-") then
_, _, book, chapter, startVerse, stopVerse =
string.find(verseSpec, "%s-(.+)%s+(%d+):(%d+)-(%d+)")
else
_, _, book, chapter, startVerse =
string.find(verseSpec, "%s-(.+)%s+(%d+):(%d+)")
end
local function contextLink()
return book .. "#" .. chapter .. "-" .. startVerse
end
local function blockquote(quote, verse, contextLink)
return "<blockquote>" .. quote .. "<div style=\"text-align: right\">" ..
"<span class=\"navigation-not-searchable\">'''[[" ..
contextLink .. "|" .. string.gsub(verse, "%s", " ") ..
"]]'''</span></div></blockquote>"
end
local function renderVerse(verseName, verseNumber)
local wikiText = mw.title.new(verseName, verseNamespace()):getContent()
if not wikiText then error("Invalid Verse Number: " .. verseSpec) end
local function addVerseNumber(wikiText)
if verseNumber == 1 then
return (string.gsub(wikiText, "^", "<big>'''" .. chapter .. "'''</big> "))
end
return (string.gsub(wikiText, "^", "<sup>'''" .. verseNumber .. "'''</sup> "))
end
local process = {}
if not showPilcrow then table.insert(process, removePilcrow) end
if stopVerse then table.insert(process, addVerseNumber) end
if #process > 0 then return compose(unpack(process))(wikiText) end
return wikiText
end
local function renderConcat()
local process = {}
if indent then table.insert(process, addIndent) end
table.insert(process, addDoubleSpace)
if #process > 0 then return compose(unpack(process))("") end
return " "
end
local function renderQuote(verses)
if indent then return addIndent(table.concat(verses, renderConcat())) end
return table.concat(verses, renderConcat())
end
local verses = {}
for i = startVerse, (stopVerse and stopVerse or startVerse) do
table.insert(verses, renderVerse(book .. " " .. chapter .. ":" .. i, i))
end
return blockquote(renderQuote(verses), verseSpec, contextLink())
end
function p.standard(frame)
local args = getArgs(frame)
local stringToBoolean = { ["true"] = true, ["false"] = false }
return renderVerses(
args[1]
, stringToBoolean[args.showVerseNumber]
, stringToBoolean[args.showPilcrow]
, stringToBoolean[args.singleSpace]
, stringToBoolean[args.doubleSpace]
, stringToBoolean[args.indent]
)
end
return p