Module:Infocard: Difference between revisions
From Halopedia, the Halo wiki
No edit summary |
No edit summary |
||
Line 22: | Line 22: | ||
-- Register render function | -- Register render function | ||
function result.render() | function result.render() | ||
local output = '{| class="wikitable infocard" ' | 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' ] .. ' ' | ||
output = output .. '|- ' | output = output .. '|- \n' | ||
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' ] .. ' ' | ||
output = output .. '|- ' | output = output .. '|- \n' | ||
end | end | ||
output = output .. '|}' | output = output .. '|}' |
Revision as of 17:29, 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' ] .. ' '
output = output .. '|- \n'
end
for i, v in ipairs( result[ 'data' ] ) do
output = output .. '! ' .. v[ 'key' ] .. ' '
output = output .. '| ' .. v[ 'value' ] .. ' '
output = output .. '|- \n'
end
output = output .. '|}'
return output
end
-- Return infocard
return result
end
return infocard