FANDOM

 
34,838 Pages

local Gallery = {}
----------------------------
-- Libraries of functions --
----------------------------
-- Parses invocation and template parameters, trims whitespace, and removes blanks.
local getArgs = require('Dev:Arguments').getArgs
 
----------------------------------------------------------
-- Public functions (called from a Template or article) --
----------------------------------------------------------
-- Interacts with the template
function Gallery.makeTable(frame)
  local t = getArgs(frame, { trim = true, removeBlanks = true, parentOnly = true })
  return (t['img1'] or t['txt1'])
    and Gallery._makeTable(t)
    or nil
end
 
-- Internal logic
function Gallery._makeTable(args)
    local placeholder = string.format(
        '[['..'%s|%s|link=%s]]',
        'File:MinifigPlaceholder.png',
        'x155px',
        'Special:Upload'
    )
 
    -- SMW logic
    local dataset = {}
    for entry = 1, 16 do
        if args['img' .. entry] then
            table.insert(dataset, ('%s=%s'):format('img' .. entry, args['img' .. entry]) )
        end
        if args['txt' .. entry] then 
            table.insert(dataset, ('%s=%s'):format('txt' .. entry, args['txt' .. entry]) )
        end
    end
    mw.smw.set( dataset )
 
    local envelope = mw.html.create('div')
        :css('width', args.condense and '65%' or '95%')
        :css('margin', 'auto')
        :css('border','1px solid #CCCCCC')
        :css('overflow','auto')
        :css('white-space','nowrap')
    local wikitable = mw.html.create('table')
        :css('margin','0 auto')
 
 
        -- image row
        wikitable:tag('tr')
    for imgEntry = 1, 60 do
        if args['img' .. imgEntry] then
        wikitable:tag('td'):wikitext(
            string.format(
                '[['..'%s|%s|%s]]',
                'File:' .. args['img' .. imgEntry],
                'x155px',
                'center'
            )
        )
        elseif args['txt' .. imgEntry] then 
            wikitable:tag('td'):wikitext(placeholder)
        end
    end
        wikitable:done()
 
 
        -- label row
        wikitable:tag('tr')
    for labelEntry = 1, 60 do
        if args['txt' .. labelEntry] then
        wikitable:tag('td'):css('width','135px'):css('text-align','center')
        :wikitext(args['txt' .. labelEntry]):done()
        end
    end
        wikitable:done()
 
    envelope:node(wikitable)
    return tostring(envelope)
end
 
return Gallery
Community content is available under CC-BY-SA unless otherwise noted.