Module:HtmlUtil

local m_team = require('Module:Team') local p = {}

function p.makeFootnoteN(n) if n and n ~= "" then return string.format(' %s ', n)	end return "" end

function p.vsAlign(team1, team2, vs, tbl) if not tbl then tbl = mw.html.create("div") end tbl:addClass('vs-align-outer') tbl:tag("div") :addClass('vs-align-left') :wikitext(team1) :done :tag("div") :addClass('vs-align-vs') :wikitext(vs or " vs ") :done :tag("div") :addClass('vs-align-right') :wikitext(team2) :done return tbl end

function p.teamsVsAlign(team1, team2) return p.vsAlign(m_team.leftshortlinked(team1), m_team.rightshortlinked(team2)) end

function p.vsAlignStr(team1, team2) return tostring(p.vsAlign(team1, team2)) end

function p.teamsVsAlignStr(team1, team2) return tostring(p.teamsVsAlign(team1, team2)) end

function p.makeNodeFromWikitext(text) local tbl = mw.html.create :wikitext(text) return tbl end

-- this function only makes the inner divs; it does not put the content into a table to restrict width, that's up to the parent function -- as such, this adds to an existing html object and does not create its own -- while content is a table, padding is a constant because why would you want variable padding -- the name of this function is inherited from the template BlockBox function p.blockBoxContent(content, padding, tbl) for k, v in ipairs(content) do		div = tbl:tag('div') div:css({			display = "inline-block",			['vertical-align'] = 'top',		}) if padding and k ~= #content then div:css('padding-right',padding) end div:wikitext(v) end return end

function p.blockBox(content, padding) local tbl = mw.html.create('table') :addClass('blockbox') local tr = tbl:tag('tr') local td = tr:tag('td') p.blockBoxContent(content, padding, td) return tbl end

function p.makeEmptySortRow(tbl, n)	local tr = tbl:tag('tr'):css('font-size','60%') for i = 1, n do		tr:tag('th') :wikitext(' ') end return end

function p.makeEmptyWidthRow(tbl, widths) local tr = tbl:tag('tr'):addClass('empty-width-row') for _, v in ipairs(widths) do		tr:tag('td'):css('width', v):wikitext(' ') end return end

function p.makeEmptyWidthRowPX(tbl, widths) local tr = tbl:tag('tr'):addClass('empty-width-row') for _, v in ipairs(widths) do tr:tag('td'):css('width', v .. 'px'):wikitext(' ') end return end

function p.makeColspanHeader(tbl, display, colspan, class, width) local tr = tbl:tag('tr'):addClass(class) local th = tr:tag('th'):attr('colspan', colspan):wikitext(display) if width then th:cssText(('width:%spx'):format(width)) end end

function p.makeHeader(tbl, data, classes) if not classes then classes = {} end local class = type(classes) == 'string' and classes local tr = tbl:tag('tr'):addClass(classes.row) for i, v in ipairs(data) do		tr:tag('th'):addClass(class or classes[i] or ''):wikitext(v) end return end

function p.printRowsByArray(tbl, data) for _, row in ipairs(data) do		tbl:tag('tr') for _, cell in ipairs(row) do			tbl:tag('td'):wikitext(cell) end end return end

function p.printRowsByList(tbl, data, list) for _, row in ipairs(data) do		tbl:tag('tr') for _, item in ipairs(list) do			tbl:tag('td'):wikitext(row[item]) end end return end

function p.printRowsByListInDict(tbl, data, list) for _, v in ipairs(data) do		tbl:tag('tr') for _, item in ipairs(list) do			tbl:tag('td'):wikitext(data[v][item]) end end return end

function p.printHelpText(div, text) local questionmark = div:tag('div') :addClass('helptext-questionmark') questionmark:tag('div') :addClass('helptext') :wikitext(text) end

function p.clear(tbl) if not tbl then tbl = mw.html.create end tbl:tag('div'):addClass('clear') return tbl end

return p