Module:BibleQuote
Documentation for this module may be created at Module:BibleQuote/doc
local p = {} --p stands for package
local function verseNamespace()
return "Template"
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 expandTemplate(title, ...)
-- return mw.getCurrentFrame():expandTemplate { title = title };
-- end
local function preProcess(text)
return mw.getCurrentFrame():preprocess(text);
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)
local _, _, book, chapter, startVerse, stopVerse =
string.find(verseSpec, "%s-(.+)%s+(%d+):(%d+)-(%d+)")
local verses = {}
local function renderVerse(verseName, verseNumber, singleSpace, doubleSpace, indent)
local wikiText = mw.title.new(verseName, verseNamespace()):getContent()
local function addVerseNumber(wikiText)
return (string.gsub(wikiText, "^", "<sup>'''" .. verseNumber .. "'''</sup> "))
end
local process = {}
if not showPilcrow then table.insert(process, removePilcrow) end
if showVerseNumber then table.insert(process, addVerseNumber) end
if doubleSpace then
table.insert(process, addDoubleSpace)
elseif singleSpace then
table.insert(process, addSingleSpace)
end
if indent then table.insert(process, addIndent) end
if #process > 0 then return compose(unpack(process))(wikiText) end
return preProcess(wikiText)
end
if stopVerse == nil then return renderVerse(verseSpec, startVerse) end
for i = startVerse, stopVerse, 1 do
table.insert(verses, renderVerse(book .. " " .. chapter .. ":" .. i, i))
end
return table.concat(verses, " ")
end
local function addChapterNumber(verse, number)
return (string.gsub(verse, "^", ""))
end
function p.standard(frame)
local stringToBoolean = { ["true"] = true, ["false"] = false }
return renderVerses(
frame.args[1]
, stringToBoolean[frame.args.showVerseNumber]
, stringToBoolean[frame.args.showPilcrow]
, stringToBoolean[frame.args.singleSpace]
, stringToBoolean[frame.args.doubleSpace]
, stringToBoolean[frame.args.indent]
)
end
return p