Module:BattleInfobox: Difference between revisions
Jump to navigation
Jump to search
(Created page with "-- Module:BattleInfobox local p = {} function p.infobox(frame) local args = frame:getParent().args -- Function to create table rows local function makeRow(label, content) if content and content ~= "" then return string.format("|-\n! style=\"background: #eaecf0; text-align: left; padding: 2px 5px;\" | %s\n| style=\"text-align: left; padding: 2px 5px;\" | %s\n", label, content) else return "" end end l...") |
No edit summary |
||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
Line 6: | Line 4: | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
local function makeRow(label, content) | local function makeRow(label, content) | ||
if content and content ~= "" then | if content and content ~= "" then | ||
Line 27: | Line 24: | ||
table.insert(result, makeRow("Result", args.result)) | table.insert(result, makeRow("Result", args.result)) | ||
table.insert(result, "|-\n! | table.insert(result, "|-\n! colspan=\"2\" style=\"background: #eaecf0; text-align: left; padding: 2px 5px;\" | Combatants") | ||
table.insert(result, "|-\n| style=\" | table.insert(result, "|-\n| style=\"text-align: left; padding: 2px 5px;\" | " .. (args.combatant1 or "") .. "\n| style=\"text-align: left; padding: 2px 5px;\" | " .. (args.combatant2 or "")) | ||
table.insert(result, "|-\n! | table.insert(result, "|-\n! colspan=\"2\" style=\"background: #eaecf0; text-align: left; padding: 2px 5px;\" | Commanders") | ||
table.insert(result, "|-\n| style=\" | table.insert(result, "|-\n| style=\"text-align: left; padding: 2px 5px;\" | " .. (args.commander1 or "") .. "\n| style=\"text-align: left; padding: 2px 5px;\" | " .. (args.commander2 or "")) | ||
table.insert(result, "|-\n! | table.insert(result, "|-\n! colspan=\"2\" style=\"background: #eaecf0; text-align: left; padding: 2px 5px;\" | Strength") | ||
table.insert(result, "|-\n| style=\" | table.insert(result, "|-\n| style=\"text-align: left; padding: 2px 5px;\" | " .. (args.strength1 or "") .. "\n| style=\"text-align: left; padding: 2px 5px;\" | " .. (args.strength2 or "")) | ||
table.insert(result, "|-\n! | table.insert(result, "|-\n! colspan=\"2\" style=\"background: #eaecf0; text-align: left; padding: 2px 5px;\" | Casualties and losses") | ||
table.insert(result, "|-\n| style=\" | table.insert(result, "|-\n| style=\"text-align: left; padding: 2px 5px;\" | " .. (args.casualties1 or "") .. "\n| style=\"text-align: left; padding: 2px 5px;\" | " .. (args.casualties2 or "")) | ||
table.insert(result, "|}\n</div>") | table.insert(result, "|}\n</div>") |
Revision as of 18:32, 29 May 2024
Documentation for this module may be created at Module:BattleInfobox/doc
local p = {} function p.infobox(frame) local args = frame:getParent().args local function makeRow(label, content) if content and content ~= "" then return string.format("|-\n! style=\"background: #eaecf0; text-align: left; padding: 2px 5px;\" | %s\n| style=\"text-align: left; padding: 2px 5px;\" | %s\n", label, content) else return "" end end local result = {} table.insert(result, '<div style="float: right; clear: right; margin: 0 0 1em 1em; width: 300px; border: 1px solid #a2a9b1; background: #f8f9fa; padding: 5px; font-size: 90%;">') table.insert(result, '{| style="width: 100%; border-collapse: collapse; border-spacing: 0;"') table.insert(result, string.format('|-\n| colspan="2" style="background: #ccddee; text-align: center; font-size: 110%%; font-weight: bold;" | %s', args.name or "")) table.insert(result, string.format('|-\n| colspan="2" style="text-align: center;" | [[File:%s|250px|alt=%s]]', args.image or "", args.image_alt or "")) table.insert(result, string.format('|-\n| colspan="2" style="text-align: center;" | %s', args.image_caption or "")) table.insert(result, makeRow("Date", args.date)) table.insert(result, makeRow("Location", args.location)) table.insert(result, makeRow("Result", args.result)) table.insert(result, "|-\n! colspan=\"2\" style=\"background: #eaecf0; text-align: left; padding: 2px 5px;\" | Combatants") table.insert(result, "|-\n| style=\"text-align: left; padding: 2px 5px;\" | " .. (args.combatant1 or "") .. "\n| style=\"text-align: left; padding: 2px 5px;\" | " .. (args.combatant2 or "")) table.insert(result, "|-\n! colspan=\"2\" style=\"background: #eaecf0; text-align: left; padding: 2px 5px;\" | Commanders") table.insert(result, "|-\n| style=\"text-align: left; padding: 2px 5px;\" | " .. (args.commander1 or "") .. "\n| style=\"text-align: left; padding: 2px 5px;\" | " .. (args.commander2 or "")) table.insert(result, "|-\n! colspan=\"2\" style=\"background: #eaecf0; text-align: left; padding: 2px 5px;\" | Strength") table.insert(result, "|-\n| style=\"text-align: left; padding: 2px 5px;\" | " .. (args.strength1 or "") .. "\n| style=\"text-align: left; padding: 2px 5px;\" | " .. (args.strength2 or "")) table.insert(result, "|-\n! colspan=\"2\" style=\"background: #eaecf0; text-align: left; padding: 2px 5px;\" | Casualties and losses") table.insert(result, "|-\n| style=\"text-align: left; padding: 2px 5px;\" | " .. (args.casualties1 or "") .. "\n| style=\"text-align: left; padding: 2px 5px;\" | " .. (args.casualties2 or "")) table.insert(result, "|}\n</div>") return table.concat(result) end return p