Module:Infocard: Difference between revisions
From Halopedia, the Halo wiki
No edit summary |
No edit summary |
||
Line 24: | Line 24: | ||
local output = '{| class="wikitable infocard" \n' | local output = '{| class="wikitable infocard" \n' | ||
if result[ 'title' ] ~= nil and result[ 'title' ] ~= '' then | if result[ 'title' ] ~= nil and result[ 'title' ] ~= '' then | ||
output = output .. '! colspan=2 | ' .. result[ 'title' ] .. ' ' | output = output .. '! colspan=2 | ' .. result[ 'title' ] .. '\n' | ||
output = output .. '|- | output = output .. '|- ' | ||
end | end | ||
for i, v in ipairs( result[ 'data' ] ) do | for i, v in ipairs( result[ 'data' ] ) do | ||
output = output .. '! ' .. v[ 'key' ] .. ' ' | output = output .. '! ' .. v[ 'key' ] .. ' ' | ||
output = output .. '| ' .. v[ 'value' ] .. ' ' | output = output .. '| ' .. v[ 'value' ] .. '\n' | ||
output = output .. '|- | output = output .. '|- ' | ||
end | end | ||
output = output .. '|}' | output = output .. '|}' |
Revision as of 17:30, September 28, 2020
Documentation for this module may be created at ModuleDoc:Infocard
local infocard = {}
function infocard.new()
-- Create a new, blank infocard
local result = { [ 'data' ] = {}, [ 'title' ] = nil }
-- Register withTitle function
function result.withTitle( title )
result[ 'title' ] = tostring( title )
return result
end
-- Register withField function
function result.withField( key, value )
table.insert( result[ 'data' ], {
[ 'key' ] = tostring( key ),
[ 'value' ] = tostring( value )
} )
return result
end
-- Register render function
function result.render()
local output = '{| class="wikitable infocard" \n'
if result[ 'title' ] ~= nil and result[ 'title' ] ~= '' then
output = output .. '! colspan=2 | ' .. result[ 'title' ] .. '\n'
output = output .. '|- '
end
for i, v in ipairs( result[ 'data' ] ) do
output = output .. '! ' .. v[ 'key' ] .. ' '
output = output .. '| ' .. v[ 'value' ] .. '\n'
output = output .. '|- '
end
output = output .. '|}'
return output
end
-- Return infocard
return result
end
return infocard