Module:Item Information

From Heavenly Wiki
Jump to navigation Jump to search

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

local p = {}

local paramTest = require('Module:Paramtest')
local onMain = require('Module:Mainonly').on_main
local yesNo = require('Module:Yesno')

function buildRow(item, info)
    local row = mw.html.create('tr')
    row:tag('td'):wikitext(item)
    row:tag('td'):wikitext(info or 'N/A')
    return row
end

function p._main(args)
    local ret = mw.html.create('table'):addClass('wikitable sticky-header')
    
    if(paramTest.has_content(args.title)) then
        ret:tag('caption'):wikitext(args.title)
    end
    
    -- Create header row
    ret:tag('tr')
        :tag('th'):wikitext('Item'):done()
        :tag('th'):wikitext('Additional Information'):done()
    
    -- Add item rows
    for i = 1, 20 do  -- Support up to 20 items
        local item = args['item' .. i]
        local info = args['info' .. i]
        
        if(paramTest.has_content(item)) then
            ret:node(buildRow(item, info))
        end
    end
    
    return ret
end

function p.main(frame)
    local args = frame:getParent().args
    return p._main(args)
end

return p