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 1: Line 1:
local p = {}
local p = {}


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


Line 10: Line 10:
     :done()
     :done()


     return tostring(html)
     return html
end
end


-- main entry point
function p.data(frame)
function p.thumbwall(frame)
  local args = frame:getParent().args or {}
    local args   = frame:getParent().args
  local title = args[1] or args['title'] or 'Navigate'
    local title = args[1] or 'Navigate'
 
    local thumbs = {}
  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')


    for i = 2, #args do
local i = 1
        if args[i] and args[i] ~= '' then
while args['label' .. i] do
            table.insert(thumbs, args[i])
local label = args['label' .. i]
        end
local image = args['image' .. i] or ''
    end
local target = args['target' .. i] or label
        html:node(renderRow(label, image, target))
    i = i + 1
end


    -- split each line into img|caption|target (target optional)
   return html
    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
end
return p

Revision as of 12:53, 15 March 2026

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

local p = {}

local function renderThumb(caption, img, target)
    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 html
end

function p.data(frame)
  local args = frame:getParent().args or {}
  local title = args[1] or args['title'] or 'Navigate'
  
  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')

	local i = 1
	while args['label' .. i] do
		local label = args['label' .. i]
		local image = args['image' .. i] or ''
		local target = args['target' .. i] or label
        html:node(renderRow(label, image, target))
    	i = i + 1
	end

  return html
end