Module:StoreTableHeader

From Discord Dungeons Wiki
Revision as of 12:51, 3 April 2022 by Mackan (talk | contribs)
Jump to navigation Jump to search

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

local p = {}

local params = require('Module:Paramtest')
local yesno = require('Module:Yesno')
local var = mw.ext.VariablesLua

function p.main(frame)
    local args = frame:getParent().args
    local currency,namenotes,smw,hideimage,hidebuy,hidesell = params.defaults{
		{args.currency,'Gold'},
		{args.namenotes,''},
		{args.smw,'yes'},
		{args.hideimage,'no'},
		{args.hidebuy,'no'},
		{args.hidesell,'no'},
		{args.hidelevel, 'no'},
	}
    var.vardefine('Currency', currency)
    var.vardefine('NameNotes', namenotes)
    var.vardefine('smw', smw)
    var.vardefine('hideImage', hideimage)
    var.vardefine('hideBuy', hidebuy)
    var.vardefine('hideSell', hidesell)
    var.vardefine('hideLevel', hidelevel)
    
    local ret = mw.html.create('')

    ret:tag('tr')
    local colspan = yesno(hideimage) and 1 or 2
    ret:tag('th'):attr('colspan', colspan):wikitext('Item'):done()
    if not(yesno(hidesell)) then
        ret:tag('th'):attr('data-sort-type', 'number'):wikitext('Price<br>sold at'):done()
    end
    if not(yesno(hidebuy)) then
        ret:tag('th'):attr('data-sort-type', 'number'):wikitext('Price<br>bought at'):done()
    end
	if not(yesno(hidelevel)) then
        ret:tag('th'):attr('data-sort-type', 'number'):wikitext('Level'):done()
    end
    local i = 1
    while args['column' .. i] do
        ret:tag('th'):attr('data-sort-type', 'number'):wikitext(args['column' .. i]):done()
        i = i+1
    end
    ret:done()
    return '<table class="wikitable sortable" style="text-align:center; margin:0;" cellpadding="2" cellspacing="0">' .. tostring(ret)
end
    
return p