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

Difference between revisions of "Module:SB Infobox Begin Test"

From Starbase wiki
Jump to navigation Jump to search
m
m
 
(One intermediate revision by the same user not shown)
Line 2: Line 2:
local p = {}
local p = {}


local function switch_key_val(tbl)
function switch_key_val(tbl)
     local rtbl = {}
     local rtbl = {}
     for k,v in pairs(tbl) do
     for k,v in pairs(tbl) do
Line 12: Line 12:
function p.main(frame)
function p.main(frame)
local args = getArgs(frame)
local args = getArgs(frame)
return args
return p._main(args)
end
end


Line 28: Line 28:
newRow:tag('div')
newRow:tag('div')
:addClass('SB-Infobox-Cell-Header')
:addClass('SB-Infobox-Cell-Header')
:wikitext(v)
:wikitext(tostring(v))
newRow:tag('div')
newRow:tag('div')
:addClass('SB-Infobox-Cell-Body')
:addClass('SB-Infobox-Cell-Body')
:wikitext(k)
:wikitext(tostring(k))
output = newRow .. output
output = output .. tostring(newRow)
end
end
 
return tostring(output)
return string.gsub(output, "(<-- Begin -->)", "%1<div class='wrapper'></div>",  1)
end
end


Line 41: Line 40:
local output = ""
local output = ""
for k,v in pairs(args) do
for k,v in pairs(args) do
output = output .. v
output = output .. tostring(v)
end
end
return output
return tostring(output)
end
end


return p
return p

Latest revision as of 08:52, 25 May 2021

Documentation for this module may be created at Module:SB Infobox Begin Test/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('SB-Infobox-Data-Cell')
			newRow:tag('div')
				:addClass('SB-Infobox-Cell-Header')
				:wikitext(tostring(v))
			newRow:tag('div')
				:addClass('SB-Infobox-Cell-Body')
				:wikitext(tostring(k))
		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.