Sb forum speech.png DiscordLink.png FacebookLink.png RedditLink.png SteamLink.png TwitterLink.png YoutubeLink.png

Difference between revisions of "Module:SB Infobox Begin"

From Starbase wiki
Jump to navigation Jump to search
Line 27: Line 27:
:addClass('Spaceship-Info-Data-Cell')
:addClass('Spaceship-Info-Data-Cell')
newRow:tag('div')
newRow:tag('div')
:addClass('Spaceship-Info-Data-Header')
:addClass('Spaceship-Info-Header')
:wikitext(tostring(k))
:wikitext(tostring(k))
newRow:tag('div')
newRow:tag('div')
:addClass('Spaceship-Info-Data-Body')
:addClass('Spaceship-Info-Body')
:wikitext(tostring(v))
:wikitext(tostring(v))
output = output .. tostring(newRow)
output = output .. tostring(newRow)

Revision as of 21:07, 17 May 2021

Documentation for this module may be created at Module:SB Infobox Begin/doc

local getArgs = require('Module:Arguments').getArgs
local p = {}

function switch_key_val(tbl)
    local rtbl = {}
    for k,v in pairs(tbl) do
        rtbl[v] = k
    end
    return rtbl
end

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

function p.section(frame)
	local args = getArgs(frame)
	local remap = switch_key_val(args)
	return p._section(remap)
end

function p._section(args)
	local output = ""
	for k,v in pairs(args) do
		local newRow = mw.html.create('div')
			:addClass('Spaceship-Info-Data-Cell')
			newRow:tag('div')
				:addClass('Spaceship-Info-Header')
				:wikitext(tostring(k))
			newRow:tag('div')
				:addClass('Spaceship-Info-Body')
				:wikitext(tostring(v))
		output = output .. tostring(newRow)
	end
	return tostring(output)
end

function p._main(args)
	local output = ""
	for k,v in pairs(args) do
		output = output .. tostring(v)
	end
	return tostring(output)
end

return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies.