Module:BattleInfobox: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
(3 intermediate revisions by the same user not shown) | |||
Line 6: | Line 6: | ||
local function makeRow(label, content) | local function makeRow(label, content) | ||
if content and content ~= "" then | 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 | return string.format("|-\n! style=\"background: #eaecf0; text-align: left; padding: 2px 5px;\" | %s\n| style=\"text-align: left; padding: 2px 5px;\" | %s", label, content) | ||
else | else | ||
return "" | return "" | ||
Line 13: | Line 13: | ||
local result = {} | local result = {} | ||
table.insert(result, ' | table.insert(result, '{| class="wikitable" 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 | if args.name then | ||
table.insert(result, string.format('|-\n| colspan="2" style="text-align: center;" | [[File:%s|250px|alt=%s]]', args.image | table.insert(result, string.format('|-\n| colspan="2" style="background: #ccddee; text-align: center; font-size: 110%%; font-weight: bold;" | %s', args.name)) | ||
table.insert(result, string.format('|-\n| colspan="2" style="text-align: center;" | %s', args.image_caption | end | ||
if args.image then | |||
table.insert(result, string.format('|-\n| colspan="2" style="text-align: center;" | [[File:%s|250px|alt=%s]]', args.image, args.image_alt or "")) | |||
end | |||
if args.image_caption then | |||
table.insert(result, string.format('|-\n| colspan="2" style="text-align: center;" | %s', args.image_caption)) | |||
end | |||
table.insert(result, makeRow("Date", args.date)) | table.insert(result, makeRow("Date", args.date)) | ||
Line 25: | Line 32: | ||
table.insert(result, "|-\n! colspan=\"2\" style=\"background: #eaecf0; text-align: left; padding: 2px 5px;\" | Combatants") | table.insert(result, "|-\n! colspan=\"2\" style=\"background: #eaecf0; text-align: left; padding: 2px 5px;\" | Combatants") | ||
table.insert(result, | table.insert(result, string.format('|-\n| style="text-align: left; padding: 2px 5px;" | %s', args.combatant1 or "")) | ||
table.insert(result, string.format('| style="text-align: left; padding: 2px 5px;" | %s', args.combatant2 or "")) | |||
table.insert(result, "|-\n! colspan=\"2\" style=\"background: #eaecf0; text-align: left; padding: 2px 5px;\" | Commanders") | table.insert(result, "|-\n! colspan=\"2\" style=\"background: #eaecf0; text-align: left; padding: 2px 5px;\" | Commanders") | ||
table.insert(result, | table.insert(result, string.format('|-\n| style="text-align: left; padding: 2px 5px;" | %s', args.commander1 or "")) | ||
table.insert(result, string.format('| style="text-align: left; padding: 2px 5px;" | %s', args.commander2 or "")) | |||
table.insert(result, "|-\n! colspan=\"2\" style=\"background: #eaecf0; text-align: left; padding: 2px 5px;\" | Strength") | table.insert(result, "|-\n! colspan=\"2\" style=\"background: #eaecf0; text-align: left; padding: 2px 5px;\" | Strength") | ||
table.insert(result, | table.insert(result, string.format('|-\n| style="text-align: left; padding: 2px 5px;" | %s', args.strength1 or "")) | ||
table.insert(result, string.format('| style="text-align: left; padding: 2px 5px;" | %s', 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! colspan=\"2\" style=\"background: #eaecf0; text-align: left; padding: 2px 5px;\" | Casualties and losses") | ||
table.insert(result, | table.insert(result, string.format('|-\n| style="text-align: left; padding: 2px 5px;" | %s', args.casualties1 or "")) | ||
table.insert(result, string.format('| style="text-align: left; padding: 2px 5px;" | %s', args.casualties2 or "")) | |||
table.insert(result, "|}\n | table.insert(result, "|}\n") | ||
return table.concat(result) | return table.concat(result) |
Latest revision as of 18:53, 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", label, content) else return "" end end local result = {} table.insert(result, '{| class="wikitable" style="width: 100%; border-collapse: collapse; border-spacing: 0;"') if args.name then table.insert(result, string.format('|-\n| colspan="2" style="background: #ccddee; text-align: center; font-size: 110%%; font-weight: bold;" | %s', args.name)) end if args.image then table.insert(result, string.format('|-\n| colspan="2" style="text-align: center;" | [[File:%s|250px|alt=%s]]', args.image, args.image_alt or "")) end if args.image_caption then table.insert(result, string.format('|-\n| colspan="2" style="text-align: center;" | %s', args.image_caption)) end 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, string.format('|-\n| style="text-align: left; padding: 2px 5px;" | %s', args.combatant1 or "")) table.insert(result, string.format('| style="text-align: left; padding: 2px 5px;" | %s', args.combatant2 or "")) table.insert(result, "|-\n! colspan=\"2\" style=\"background: #eaecf0; text-align: left; padding: 2px 5px;\" | Commanders") table.insert(result, string.format('|-\n| style="text-align: left; padding: 2px 5px;" | %s', args.commander1 or "")) table.insert(result, string.format('| style="text-align: left; padding: 2px 5px;" | %s', args.commander2 or "")) table.insert(result, "|-\n! colspan=\"2\" style=\"background: #eaecf0; text-align: left; padding: 2px 5px;\" | Strength") table.insert(result, string.format('|-\n| style="text-align: left; padding: 2px 5px;" | %s', args.strength1 or "")) table.insert(result, string.format('| style="text-align: left; padding: 2px 5px;" | %s', args.strength2 or "")) table.insert(result, "|-\n! colspan=\"2\" style=\"background: #eaecf0; text-align: left; padding: 2px 5px;\" | Casualties and losses") table.insert(result, string.format('|-\n| style="text-align: left; padding: 2px 5px;" | %s', args.casualties1 or "")) table.insert(result, string.format('| style="text-align: left; padding: 2px 5px;" | %s', args.casualties2 or "")) table.insert(result, "|}\n") return table.concat(result) end return p