Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Infobox unit

From Sekaipedia
Revision as of 07:37, 22 January 2022 by ChaoticShadow (talk | contribs)

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, dFunc = formatMembers },
			{ name = 'virtual singers', pFunc = splitList, dFunc = 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
Cookies help us deliver our services. By using our services, you agree to our use of cookies.