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

Module:Infobox unit: Difference between revisions

From Sekaipedia
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 categories = ""


local function split(inputstr, sep)
local function split(inputstr, sep)
Line 28: Line 27:
end
end


local function formatMembers(arg)
local function splitList(str)
if arg then
if str == nil then
return nil
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
end
local list = mw.text.split(str, ',')
return nil
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
end


Line 47: Line 61:
infobox:setName('Infobox unit')
infobox:setName('Infobox unit')
:setParams{
:setWidth("330px")
{ name = 'name', default = mw.title.getCurrentTitle().text },
infobox:setParams{
{ name = 'unit name', default = mw.title.getCurrentTitle().text },
{ name = 'image', dFunc = formatImage },
{ name = 'unit image', func = formatImage },
{ name = 'japanese' },
{ name = 'japanese' },
{ name = 'romaji' },
{ name = 'romaji' },
{ name = 'english' },
{ name = 'english' },
{ name = 'logo', dFunc = formatLogo },
{ name = 'logo', func = formatLogo },
{ name = 'members', pFunc = splitList, func = formatMembers },
{ name = 'members', func = formatMembers },
{ name = 'virtual singers', pFunc = splitList, func = formatMembers }
}
{ name = 'virtual singers', func = formatMembers }
}
infobox
:setArgs(args)
:setArgs(args)
:processArgs()


infobox
infobox
:addHeader({ tag = 'argth', content = 'unit name' })
:addHeader({ tag = 'argth', content = 'name' })
:addImage{{ tag = 'argtd', content = 'unit image' }}
:addImage{{ tag = 'argtd', content = 'image' }}
:addRow(
:addRow(
{
{
{ tag = 'th', content = 'Japanese', colspan = 12 },
{ tag = 'th', content = 'Japanese' },
{ tag = 'argtd', content = 'japanese', colspan = 18 }
{ tag = 'argtd', content = 'japanese' }
},
},
{ hideIfEmpty = { 'japanese' } }
{ hideIfEmpty = { 'japanese' } }
Line 74: Line 86:
:addRow(
:addRow(
{
{
{ tag = 'th', content = 'Romaji', colspan = 12 },
{ tag = 'th', content = 'Romaji' },
{ tag = 'argtd', content = 'romaji', colspan = 18 }
{ tag = 'argtd', content = 'romaji' }
},
},
{ hideIfEmpty = { 'romaji' } }
{ hideIfEmpty = { 'romaji' } }
Line 81: Line 93:
:addRow(
:addRow(
{
{
{ tag = 'th', content = 'English', colspan = 12 },
{ tag = 'th', content = 'English' },
{ tag = 'argtd', content = 'english', colspan = 18 }
{ tag = 'argtd', content = 'english' }
},
},
{ hideIfEmpty = { 'english' } }
{ hideIfEmpty = { 'english' } }
Line 91: Line 103:
:addRow(
:addRow(
{
{
{ tag = 'th', content = 'Members', colspan = 12 },
{ tag = 'th', content = 'Members' },
{ tag = 'argtd', content = 'members', colspan = 18 }
{ tag = 'argtd', content = 'members' }
},
},
{ hideIfEmpty = { 'members' } }
{ hideIfEmpty = { 'members' } }
Line 98: Line 110:
:addRow(
:addRow(
{
{
{ tag = 'th', content = 'Virtual Singers', colspan = 12 },
{ tag = 'th', content = 'Virtual Singers' },
{ tag = 'argtd', content = 'virtual singers', colspan = 18 }
{ tag = 'argtd', content = 'virtual singers' }
},
},
{ hideIfEmpty = { 'virtual singers' } }
{ hideIfEmpty = { 'virtual singers' } }
)
)
local categories = ""
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

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
Cookies help us deliver our services. By using our services, you agree to our use of cookies.