Module:BibleQuote: Difference between revisions

From BibleVerseWiki
No edit summary
No edit summary
Line 15: Line 15:
       return recurse(i + 1, chain[i](...))
       return recurse(i + 1, chain[i](...))
     end
     end
     return function(...) return recurse(1, ...) end
     return function(...) return recurse(1, ...) end
end
end
Line 23: Line 22:
         string.find(verseSpec, "%s-(.+)%s+(%d+):(%d+)-(%d+)")
         string.find(verseSpec, "%s-(.+)%s+(%d+):(%d+)-(%d+)")
     local verses = {}
     local verses = {}
     local function renderVerse(verseName, verseNumber)
     local function renderVerse(verseName, verseNumber)
         local verse = expandTemplate(verseName)
         local verse = expandTemplate(verseName)
         local function addVerseNumber(verse)
         local function addVerseNumber(verse)
             return (string.gsub(verse, "^", "<sup>"..verseNumber.."</sup>&nbsp;"))
             return (string.gsub(verse, "^", "<sup>"..verseNumber.."</sup>&nbsp;"))
         end
         end      
       
         local process = {}
         local process = {}
         if not showPilcrow then  
         if not showPilcrow then table.insert(process, removePilcrow) end
            table.insert(process, removePilcrow)  
        if showVerseNumber then table.insert(process, addVerseNumber) end
        if #process > 0 then
            return compose(unpack(process))(verse)
        else
            return verse
         end
         end
        if showVerseNumber then
            table.insert(process, addVerseNumber)
        end
        return compose(unpack(process))(verse)
    end
    if stopVerse == nil then
        return renderVerse(verseSpec, startVerse)
     end
     end
      
     if stopVerse == nil then return renderVerse(verseSpec, startVerse) end   
     for i = startVerse, stopVerse, 1 do
     for i = startVerse, stopVerse, 1 do
         table.insert(verses, renderVerse(book.." "..chapter..":"..i, startVerse))         
         table.insert(verses, renderVerse(book.." "..chapter..":"..i, startVerse))         
     end
     end
     return table.concat(verses, " ")     
     return table.concat(verses, " ")     
end
end
Line 61: Line 51:
function p.standard(frame)         
function p.standard(frame)         
     return renderVerses(  
     return renderVerses(  
          frame.args[1]
      frame.args[1]
        , frame.args.showVerseNumber or false
    , frame.args.showVerseNumber or false
        , frame.args.showPilcrow or false
    , frame.args.showPilcrow or false
        )       
    )       
end
end


return p
return p

Revision as of 04:12, 9 December 2023

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

local p = {} --p stands for package

local function removePilcrow(verse)    
    return (string.gsub(verse, "¶", ""))
end

local function expandTemplate(title, ...)
    return mw.getCurrentFrame():expandTemplate{title = title};
end

local function compose(...)    
    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)
        local verse = expandTemplate(verseName)
        local function addVerseNumber(verse)
            return (string.gsub(verse, "^", "<sup>"..verseNumber.."</sup>&nbsp;"))
        end        
        local process = {}
        if not showPilcrow then table.insert(process, removePilcrow) end
        if showVerseNumber then table.insert(process, addVerseNumber) end
        if #process > 0 then 
            return compose(unpack(process))(verse)
        else
            return verse
        end
    end
    if stopVerse == nil then return renderVerse(verseSpec, startVerse) end    
    for i = startVerse, stopVerse, 1 do
        table.insert(verses, renderVerse(book.." "..chapter..":"..i, startVerse))        
    end
    return table.concat(verses, " ")    
end



local function addChapterNumber(verse, number)
    return (string.gsub(verse, "^", ""))
end

function p.standard(frame)        
    return renderVerses( 
      frame.args[1]
    , frame.args.showVerseNumber or false
    , frame.args.showPilcrow or false
    )       
end

return p