Content added Content deleted
mNo edit summary |
mNo edit summary |
||
(15 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
-------------------------- |
-------------------------- |
||
-- Module for [[Template:Infobox |
-- Module for [[Template:Infobox unit]] |
||
------------------------ |
------------------------ |
||
local |
local getArgs = require('Module:Arguments').getArgs |
||
local |
local InfoboxBuilder = require('Module:InfoboxBuilder') |
||
local DisplayFns = require('Module:DisplayFunctions') |
|||
local ProcessingFns = require('Module:ProcessingFunctions') |
|||
local p = {} |
local p = {} |
||
⚫ | |||
local function |
local function formatMembers(members) |
||
local linkedMembers = {} |
|||
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) |
|||
table.insert(linkedMembers, "[[" .. member .. "]]") |
|||
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 formatMembers(arg) |
|||
if arg then |
|||
local split_members = utils.split(arg, ",") |
|||
⚫ | |||
split_members[i] = '[[' .. utils.trim(v) .. ']]' |
|||
end |
|||
⚫ | |||
return table.concat(split_members, "<br>") |
|||
end |
end |
||
return DisplayFns.list('unbulleted')(linkedMembers) |
|||
return nil |
|||
end |
end |
||
function p.main(frame) |
function p.main(frame) |
||
local args = |
local args = getArgs(frame) |
||
local infobox = |
local infobox = InfoboxBuilder.new(); |
||
infobox:setName('Infobox |
infobox:setName('Infobox unit') |
||
⚫ | |||
:setWidth("330px") |
|||
{ name = 'name', default = mw.title.getCurrentTitle().text }, |
|||
⚫ | |||
{ name = 'unit |
{ name = 'unit image brand new world' }, |
||
{ name = 'unit image' |
{ name = 'unit image' }, |
||
{ name = 'japanese' }, |
{ name = 'japanese' }, |
||
{ name = 'romaji' }, |
{ name = 'romaji' }, |
||
{ name = 'english' }, |
{ name = 'english' }, |
||
{ name = 'logo' |
{ name = 'logo' }, |
||
{ name = 'members', |
{ name = 'members', fn = ProcessingFns.stringToArray(',') }, |
||
{ name = 'virtual singers', |
{ name = 'virtual singers', fn = ProcessingFns.stringToArray(',') } |
||
} |
|||
infobox |
|||
:setArgs(args) |
:setArgs(args) |
||
:processArgs() |
|||
infobox |
infobox |
||
:addHeader({ tag = 'argth', content = ' |
:addHeader({ tag = 'argth', content = 'name' }) |
||
:addImage{ |
:addImage({ |
||
⚫ | |||
tag = 'argtd', |
|||
content = 'unit image brand new world', |
|||
fn = DisplayFns.image('300px'), |
|||
tabName = 'Brand New World' |
|||
}, |
|||
{ |
|||
tag = 'argtd', |
|||
content = 'unit image', |
|||
fn = DisplayFns.image('300px'), |
|||
tabName = 'Original' |
|||
}, |
|||
}) |
|||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Japanese' |
{ tag = 'th', content = 'Japanese' }, |
||
{ tag = 'argtd', content = 'japanese' |
{ tag = 'argtd', content = 'japanese' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'japanese' } } |
{ hideIfEmpty = { 'japanese' } } |
||
Line 73: | Line 64: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Romaji' |
{ tag = 'th', content = 'Romaji' }, |
||
{ tag = 'argtd', content = 'romaji' |
{ tag = 'argtd', content = 'romaji' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'romaji' } } |
{ hideIfEmpty = { 'romaji' } } |
||
Line 80: | Line 71: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'English' |
{ tag = 'th', content = 'English' }, |
||
{ tag = 'argtd', content = 'english' |
{ tag = 'argtd', content = 'english' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'english' } } |
{ hideIfEmpty = { 'english' } } |
||
) |
) |
||
:addHeader({ tag = 'th', content = 'Logo'}, { subheader = true }) |
:addHeader({ tag = 'th', content = 'Logo'}, { subheader = true }) |
||
:addImage{{ |
:addImage{{ |
||
tag = 'argtd', |
|||
content = 'logo', |
|||
fn = DisplayFns.image('200px') |
|||
}} |
|||
:addHeader({ tag = 'th', content = 'Information' }, { subheader = true }) |
:addHeader({ tag = 'th', content = 'Information' }, { subheader = true }) |
||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Members' |
{ tag = 'th', content = 'Members' }, |
||
{ tag = 'argtd', content = 'members', |
{ tag = 'argtd', content = 'members', fn = formatMembers } |
||
}, |
}, |
||
{ hideIfEmpty = { 'members' } } |
{ hideIfEmpty = { 'members' } } |
||
Line 97: | Line 92: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Virtual Singers' |
{ tag = 'th', content = 'Virtual Singers' }, |
||
{ tag = 'argtd', content = 'virtual singers', |
{ tag = 'argtd', content = 'virtual singers', fn = formatMembers } |
||
}, |
}, |
||
{ 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 |
Latest revision as of 23:08, 8 January 2024
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 InfoboxBuilder = require('Module:InfoboxBuilder')
local DisplayFns = require('Module:DisplayFunctions')
local ProcessingFns = require('Module:ProcessingFunctions')
local p = {}
local function formatMembers(members)
local linkedMembers = {}
for _, member in ipairs(members) do
table.insert(linkedMembers, "[[" .. member .. "]]")
end
return DisplayFns.list('unbulleted')(linkedMembers)
end
function p.main(frame)
local args = getArgs(frame)
local infobox = InfoboxBuilder.new();
infobox:setName('Infobox unit')
:setParams{
{ name = 'name', default = mw.title.getCurrentTitle().text },
{ name = 'unit image brand new world' },
{ name = 'unit image' },
{ name = 'japanese' },
{ name = 'romaji' },
{ name = 'english' },
{ name = 'logo' },
{ name = 'members', fn = ProcessingFns.stringToArray(',') },
{ name = 'virtual singers', fn = ProcessingFns.stringToArray(',') }
}
:setArgs(args)
:processArgs()
infobox
:addHeader({ tag = 'argth', content = 'name' })
:addImage({
{
tag = 'argtd',
content = 'unit image brand new world',
fn = DisplayFns.image('300px'),
tabName = 'Brand New World'
},
{
tag = 'argtd',
content = 'unit image',
fn = DisplayFns.image('300px'),
tabName = 'Original'
},
})
: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',
fn = DisplayFns.image('200px')
}}
:addHeader({ tag = 'th', content = 'Information' }, { subheader = true })
:addRow(
{
{ tag = 'th', content = 'Members' },
{ tag = 'argtd', content = 'members', fn = formatMembers }
},
{ hideIfEmpty = { 'members' } }
)
:addRow(
{
{ tag = 'th', content = 'Virtual Singers' },
{ tag = 'argtd', content = 'virtual singers', fn = formatMembers }
},
{ hideIfEmpty = { 'virtual singers' } }
)
local categories = ""
if mw.title.getCurrentTitle().namespace == 0 then
categories = "[[Category:Units]]" .. categories
end
return infobox:tostring() .. categories
end
return p