PC Gaming Shelter
An archive dedicated to preserving PC Gaming history and more

Module:Navigation: Difference between revisions

From PC Gaming Shelter
No edit summary
No edit summary
Line 4: Line 4:
     local caption, img, target = row[1], row[2], row[3]
     local caption, img, target = row[1], row[2], row[3]


local html = mw.html.create()
    local html = mw.html.create()
html:tag('div')
    html:tag('div')
:tag('div'):attr('data-bg', img):wikitext(string.format([[%s|%s]], target, caption)):done()
        :tag('div'):attr('data-bg', img):wikitext(string.format([[%s|%s]], target, caption)):done()
:tag('div'):wikitext(string.format([[%s|%s]], target, caption)):done()
        :tag('div'):wikitext(string.format([[%s|%s]], target, caption)):done()
:done()
    :done()
 
     return tostring(html)
     return tostring(html)
end
end


-- main entry point
function p.thumbwall(frame)
function p.thumbwall(frame)
local args = frame:getParent().args
    local args   = frame:getParent().args
local title = args[1] or 'Navigate'
    local title = args[1] or 'Navigate'
local thumbs = {}
    local thumbs = {}
for i = 2, #args do
 
    if args[i] and args[i] ~= '' then
    for i = 2, #args do
        table.insert(thumbs, args[i])
        if args[i] and args[i] ~= '' then
    end
            table.insert(thumbs, args[i])
end
        end
-- if #thumbs == 0 then return end
    end
 
    -- split each line into img|caption|target (target optional)
     local thumbTable = {}
     local thumbTable = {}
     for _, line in ipairs(thumbs) do
     for _, line in ipairs(thumbs) do
        -- Split into two or three parts (target optional)
         local img, caption, target = line:match("^%s*(.-)%s*;%s*(.-)%s*$")
         local img, caption, target = line:match("^%s*(.-)%s*;%s*(.-)%s*;%s*(.-)?%s*$")
        if not target then target = caption end   -- fallback when only 2 parts
if not target or target == '' then target = caption end
         if img and caption then
         if img and caption then
             table.insert(thumbTable, { caption, img, target })
             table.insert(thumbTable, {caption, img, target})
         end
         end
     end
     end


local wallContent = ''
    local wallContent = ''
for _, row in ipairs(thumbTable) do
    for _, row in ipairs(thumbTable) do
         wallContent = wallContent .. renderThumb(row)
         wallContent = wallContent .. renderThumb(row)
end
    end
 
    local html = mw.html.create()
    html:tag('div'):addClass('card bg-dark thumbwall')
        :tag('div'):addClass('card-header'):wikitext(title):done()
        :tag('div'):addClass('card-body'):wikitext(wallContent):done()
    :done()


local html = mw.html.create()
    return tostring(html)   -- ← convert to string
html:tag('div'):addClass('card bg-dark thumbwall')
:tag('div'):addClass('card-header'):wikitext(title):done()
:tag('div'):addClass('card-body'):wikitext(wallContent):done()
:done()
    return html
end
end


return p
return p

Revision as of 12:45, 15 March 2026

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

local p = {}

local function renderThumb(row)
    local caption, img, target = row[1], row[2], row[3]

    local html = mw.html.create()
    html:tag('div')
        :tag('div'):attr('data-bg', img):wikitext(string.format([[%s|%s]], target, caption)):done()
        :tag('div'):wikitext(string.format([[%s|%s]], target, caption)):done()
    :done()

    return tostring(html)
end

-- main entry point
function p.thumbwall(frame)
    local args   = frame:getParent().args
    local title  = args[1] or 'Navigate'
    local thumbs = {}

    for i = 2, #args do
        if args[i] and args[i] ~= '' then
            table.insert(thumbs, args[i])
        end
    end

    -- split each line into img|caption|target (target optional)
    local thumbTable = {}
    for _, line in ipairs(thumbs) do
        local img, caption, target = line:match("^%s*(.-)%s*;%s*(.-)%s*$")
        if not target then target = caption end   -- fallback when only 2 parts
        if img and caption then
            table.insert(thumbTable, {caption, img, target})
        end
    end

    local wallContent = ''
    for _, row in ipairs(thumbTable) do
        wallContent = wallContent .. renderThumb(row)
    end

    local html = mw.html.create()
    html:tag('div'):addClass('card bg-dark thumbwall')
        :tag('div'):addClass('card-header'):wikitext(title):done()
        :tag('div'):addClass('card-body'):wikitext(wallContent):done()
    :done()

    return tostring(html)   -- ← convert to string
end

return p