Content added Content deleted
m (ChaoticShadow moved page Module:Infobox Unit to Module:Infobox unit without leaving a redirect) |
(using new builder) |
||
Line 3: | Line 3: | ||
------------------------ |
------------------------ |
||
local getArgs = require('Module:Arguments').getArgs |
local getArgs = require('Module:Arguments').getArgs |
||
local builder = require('Module:InfoboxBuilder') |
local builder = require('Module:InfoboxBuilder new') |
||
local utils = require('Module:Utilities') |
local utils = require('Module:Utilities') |
||
local p = {} |
local p = {} |
||
⚫ | |||
local function split(inputstr, sep) |
local function split(inputstr, sep) |
||
Line 28: | Line 27: | ||
end |
end |
||
local function |
local function splitList(str) |
||
if |
if str == nil then |
||
⚫ | |||
⚫ | |||
for i,v in ipairs(split_members) do |
|||
split_members[i] = '[[' .. utils.trim(v) .. ']]' |
|||
⚫ | |||
⚫ | |||
return table.concat(split_members, "<br>") |
|||
end |
end |
||
⚫ | |||
⚫ | |||
for i=1,#list do |
|||
list[i] = mw.text.trim(list[i]) |
|||
⚫ | |||
⚫ | |||
return list |
|||
end |
|||
local function formatMembers(members) |
|||
if #members < 2 then |
|||
return members[1] |
|||
end |
|||
⚫ | |||
local ul = mw.html.create('ul') |
|||
for i=1,#members do |
|||
ul:tag('li') |
|||
:wikitext(members[i]) |
|||
end |
|||
return tostring(ul) |
|||
end |
end |
||
Line 47: | Line 61: | ||
infobox:setName('Infobox unit') |
infobox:setName('Infobox unit') |
||
⚫ | |||
:setWidth("330px") |
|||
{ name = 'name', default = mw.title.getCurrentTitle().text }, |
|||
⚫ | |||
{ name = ' |
{ name = 'image', dFunc = formatImage }, |
||
{ name = ' |
{ name = 'japanese' }, |
||
{ name = ' |
{ name = 'romaji' }, |
||
{ name = ' |
{ name = 'english' }, |
||
{ name = ' |
{ name = 'logo', dFunc = formatLogo }, |
||
{ name = ' |
{ name = 'members', pFunc = splitList, func = formatMembers }, |
||
{ name = ' |
{ name = 'virtual singers', pFunc = splitList, func = formatMembers } |
||
⚫ | |||
{ name = 'virtual singers', func = formatMembers } |
|||
⚫ | |||
⚫ | |||
infobox |
|||
:setArgs(args) |
:setArgs(args) |
||
:processArgs() |
|||
infobox |
infobox |
||
:addHeader({ tag = 'argth', content = ' |
:addHeader({ tag = 'argth', content = 'name' }) |
||
:addImage{{ tag = 'argtd', content = ' |
:addImage{{ tag = 'argtd', content = 'image' }} |
||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Japanese' |
{ tag = 'th', content = 'Japanese' }, |
||
{ tag = 'argtd', content = 'japanese' |
{ tag = 'argtd', content = 'japanese' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'japanese' } } |
{ hideIfEmpty = { 'japanese' } } |
||
Line 74: | Line 86: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Romaji' |
{ tag = 'th', content = 'Romaji' }, |
||
{ tag = 'argtd', content = 'romaji' |
{ tag = 'argtd', content = 'romaji' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'romaji' } } |
{ hideIfEmpty = { 'romaji' } } |
||
Line 81: | Line 93: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'English' |
{ tag = 'th', content = 'English' }, |
||
{ tag = 'argtd', content = 'english' |
{ tag = 'argtd', content = 'english' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'english' } } |
{ hideIfEmpty = { 'english' } } |
||
Line 91: | Line 103: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Members' |
{ tag = 'th', content = 'Members' }, |
||
{ tag = 'argtd', content = 'members' |
{ tag = 'argtd', content = 'members' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'members' } } |
{ hideIfEmpty = { 'members' } } |
||
Line 98: | Line 110: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Virtual Singers' |
{ tag = 'th', content = 'Virtual Singers' }, |
||
{ tag = 'argtd', content = 'virtual singers' |
{ tag = 'argtd', content = 'virtual singers' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'virtual singers' } } |
{ hideIfEmpty = { 'virtual singers' } } |
||
) |
) |
||
⚫ | |||
if mw.title.getCurrentTitle().namespace == 0 then |
if mw.title.getCurrentTitle().namespace == 0 then |
||
categories = "[[Category:Units]]" .. categories |
categories = "[[Category:Units]]" .. categories |
Revision as of 07:36, 22 January 2022
This module depends on the following other modules: |
To generate {{Infobox unit}}, invoke using the main function.
--------------------------
-- Module for [[Template:Infobox unit]]
------------------------
local getArgs = require('Module:Arguments').getArgs
local builder = require('Module:InfoboxBuilder new')
local utils = require('Module:Utilities')
local p = {}
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|200px]]", image_name)
end
local function splitList(str)
if str == nil then
return nil
end
local list = mw.text.split(str, ',')
for i=1,#list do
list[i] = mw.text.trim(list[i])
end
return list
end
local function formatMembers(members)
if #members < 2 then
return members[1]
end
local ul = mw.html.create('ul')
for i=1,#members do
ul:tag('li')
:wikitext(members[i])
end
return tostring(ul)
end
function p.main(frame)
local args = getArgs(frame)
local infobox = builder.new();
infobox:setName('Infobox unit')
:setParams{
{ name = 'name', default = mw.title.getCurrentTitle().text },
{ name = 'image', dFunc = formatImage },
{ name = 'japanese' },
{ name = 'romaji' },
{ name = 'english' },
{ name = 'logo', dFunc = formatLogo },
{ name = 'members', pFunc = splitList, func = formatMembers },
{ name = 'virtual singers', pFunc = splitList, func = formatMembers }
}
:setArgs(args)
:processArgs()
infobox
:addHeader({ tag = 'argth', content = 'name' })
:addImage{{ tag = 'argtd', content = 'image' }}
:addRow(
{
{ tag = 'th', content = 'Japanese' },
{ tag = 'argtd', content = 'japanese' }
},
{ hideIfEmpty = { 'japanese' } }
)
:addRow(
{
{ tag = 'th', content = 'Romaji' },
{ tag = 'argtd', content = 'romaji' }
},
{ hideIfEmpty = { 'romaji' } }
)
:addRow(
{
{ tag = 'th', content = 'English' },
{ tag = 'argtd', content = 'english' }
},
{ 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' },
{ tag = 'argtd', content = 'members' }
},
{ hideIfEmpty = { 'members' } }
)
:addRow(
{
{ tag = 'th', content = 'Virtual Singers' },
{ tag = 'argtd', content = 'virtual singers' }
},
{ hideIfEmpty = { 'virtual singers' } }
)
local categories = ""
if mw.title.getCurrentTitle().namespace == 0 then
categories = "[[Category:Units]]" .. categories
end
return infobox:tostring() .. categories
end
return p