Content added Content deleted
(using utils module) |
(reduce size of logo, remove arguments as import) |
||
Line 2: | Line 2: | ||
-- Module for [[Template:Infobox Unit]] |
-- Module for [[Template:Infobox Unit]] |
||
------------------------ |
------------------------ |
||
local getArgs = require('Module:Arguments').getArgs |
|||
local builder = require('Module:InfoboxBuilder') |
local builder = require('Module:InfoboxBuilder') |
||
local utils = require('Module:Utilities') |
local utils = require('Module:Utilities') |
||
Line 22: | Line 21: | ||
local function formatImage(image_name) |
local function formatImage(image_name) |
||
return string.format("[[File:%s|300px]]", image_name) |
return string.format("[[File:%s|300px]]", image_name) |
||
end |
|||
local function formatLogo(image_name) |
|||
return string.format("[[File:%s|250px]]", image_name) |
|||
end |
end |
||
Line 39: | Line 42: | ||
function p.main(frame) |
function p.main(frame) |
||
local args = |
local args = frame:getParent().args |
||
local infobox = builder.new(); |
local infobox = builder.new(); |
||
Line 50: | Line 53: | ||
{ name = 'romaji' }, |
{ name = 'romaji' }, |
||
{ name = 'english' }, |
{ name = 'english' }, |
||
{ name = 'logo', func = |
{ name = 'logo', func = formatLogo }, |
||
{ name = 'members', func = formatMembers }, |
{ name = 'members', func = formatMembers }, |
||
{ name = 'virtual singers', func = formatMembers } |
{ name = 'virtual singers', func = formatMembers } |
Revision as of 02:32, 13 November 2021
This module depends on the following other modules: |
To generate {{Infobox unit}}, invoke using the main function.
--------------------------
-- Module for [[Template:Infobox Unit]]
------------------------
local builder = require('Module:InfoboxBuilder')
local utils = require('Module:Utilities')
local p = {}
local categories = ""
local function split(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t={}
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
table.insert(t, str)
end
return t
end
local function formatImage(image_name)
return string.format("[[File:%s|300px]]", image_name)
end
local function formatLogo(image_name)
return string.format("[[File:%s|250px]]", image_name)
end
local function formatMembers(arg)
if arg then
local split_members = utils.split(arg, ",")
for i,v in ipairs(split_members) do
split_members[i] = '[[' .. utils.trim(v) .. ']]'
end
return table.concat(split_members, "<br>")
end
return nil
end
function p.main(frame)
local args = frame:getParent().args
local infobox = builder.new();
infobox:setName('Infobox Unit')
:setWidth("330px")
infobox:setParams{
{ name = 'unit name', default = mw.title.getCurrentTitle().text },
{ name = 'unit image', func = formatImage },
{ name = 'japanese' },
{ name = 'romaji' },
{ name = 'english' },
{ name = 'logo', func = formatLogo },
{ name = 'members', func = formatMembers },
{ name = 'virtual singers', func = formatMembers }
}
infobox
:setArgs(args)
infobox
:addHeader({ tag = 'argth', content = 'unit name' })
:addImage{{ tag = 'argtd', content = 'unit image' }}
:addRow(
{
{ tag = 'th', content = 'Japanese', colspan = 12 },
{ tag = 'argtd', content = 'japanese', colspan = 18 }
},
{ hideIfEmpty = { 'japanese' } }
)
:addRow(
{
{ tag = 'th', content = 'Romaji', colspan = 12 },
{ tag = 'argtd', content = 'romaji', colspan = 18 }
},
{ hideIfEmpty = { 'romaji' } }
)
:addRow(
{
{ tag = 'th', content = 'English', colspan = 12 },
{ tag = 'argtd', content = 'english', colspan = 18 }
},
{ hideIfEmpty = { 'english' } }
)
:addHeader({ tag = 'th', content = 'Logo'}, { subheader = true })
:addImage{{ tag = 'argtd', content = 'logo' }}
:addHeader({ tag = 'th', content = 'Information' }, { subheader = true })
:addRow(
{
{ tag = 'th', content = 'Members', colspan = 12 },
{ tag = 'argtd', content = 'members', colspan = 18 }
},
{ hideIfEmpty = { 'members' } }
)
:addRow(
{
{ tag = 'th', content = 'Virtual Singers', colspan = 12 },
{ tag = 'argtd', content = 'virtual singers', colspan = 18 }
},
{ hideIfEmpty = { 'virtual singers' } }
)
if mw.title.getCurrentTitle().namespace == 0 then
categories = "[[Category:Units]]" .. categories
end
return infobox:tostring() .. categories
end
return p