Module:Infobox tournament: Difference between revisions

From Sekaipedia
Content added Content deleted
mNo edit summary
No edit summary
 
(9 intermediate revisions by the same user not shown)
Line 3: Line 3:
------------------------
------------------------
local getArgs = require('Module:Arguments').getArgs
local getArgs = require('Module:Arguments').getArgs
local InfoboxBuilder = require('Module:InfoboxBuilder new')
local InfoboxBuilder = require('Module:InfoboxBuilder')
local DisplayFns = require('Module:DisplayFunctions')
local ProcessingFns = require('Module:ProcessingFunctions')


local p = {}
local p = {}

local function formatImage(imageName)
return string.format("[[File:%s|220px]]", imageName)
end


local function formatPrevious(previousTourney)
local function formatPrevious(previousTourney)
if previousTourney and previousTourney ~='' then
if previousTourney and previousTourney ~= '' then
return string.format('🡰 [[%s]]', previousTourney)
return string.format('🡰 [[%s]]', previousTourney)
end
end
return nil
return ' '
end
end


local function formatNext(nextTourney)
local function formatNext(nextTourney)
if nextTourney and nextTourney ~='' then
if nextTourney and nextTourney ~= '' then
return string.format('[[%s]] 🡲', nextTourney)
return string.format('[[%s]] 🡲', nextTourney)
end
end
return nil
return ' '
end
end


Line 35: Line 33:
:setParams{
:setParams{
{ name = 'tournament name', default = mw.title.getCurrentTitle().text },
{ name = 'tournament name', default = mw.title.getCurrentTitle().text },
{ name = 'image', dFunc = formatImage },
{ name = 'image' },
{ name = 'japanese' },
{ name = 'japanese' },
{ name = 'romaji' },
{ name = 'romaji' },
{ name = 'organizers' },
{ name = 'organizers', fn = ProcessingFns.stringToArray(',') },
{ name = 'sponsors' },
{ name = 'sponsors', fn = ProcessingFns.stringToArray(',') },
{ name = 'prize pool' },
{ name = 'prize pool' },
{ name = 'teams' },
{ name = 'teams' },
{ name = 'previous', default = '', dFunc = formatPrevious },
{ name = 'previous', default = '' },
{ name = 'next', default = '', dFunc = formatNext }
{ name = 'next', default = '' }
}
}
:setArgs(args)
:setArgs(args)
Line 51: Line 49:
:addHeader({ tag = 'argth', content = 'tournament name' })
:addHeader({ tag = 'argth', content = 'tournament name' })
:addImage({
:addImage({
{ tag = 'argtd', content = 'image' },
{ tag = 'argtd', content = 'image', fn = DisplayFns.image('220px') },
})
})
:addRow(
:addRow(
Line 68: Line 66:
)
)
:addHeader({ tag = 'th', content = 'Tournament Information' }, { subheader = true })
:addHeader({ tag = 'th', content = 'Tournament Information' }, { subheader = true })
:addRow(
:addRow({
{
{
{ tag = 'th', content = 'Organizer(s)' },
tag = 'argth',
{ tag = 'argtd', content = 'organizers' }
content = 'organizers',
fn = DisplayFns.pluralHeader({ 'Organizer', 'Organizers' })
},
{
tag = 'argtd',
content = 'organizers',
fn = DisplayFns.list('unbulleted')
}
}
)
})
:addRow(
:addRow(
{
{
{
{ tag = 'th', content = 'Sponsor(s)' },
{ tag = 'argtd', content = 'sponsors' }
tag = 'argth',
content = 'sponsors',
fn = DisplayFns.pluralHeader({ 'Sponsor', 'Sponsors' })
},
{
tag = 'argtd',
content = 'sponsors',
fn = DisplayFns.list('unbulleted')
}
},
},
{ hideIfEmpty = { 'sponsors' } }
{ hideIfEmpty = { 'sponsors' } }
)
)
:addHeader({ tag = 'th', content = 'Chronology' }, { subheader = true })
:addHeader({ tag = 'th', content = 'Chronology' }, { subheader = true })
:addRow(
:addRow({
{
{
{ tag = 'argtd', content = 'previous', colspan = 13 },
tag = 'argtd',
{ tag = 'td', content = '', colspan = 4 },
content = 'previous',
fn = formatPrevious,
{ tag = 'argtd', content = 'next', colspan = 13 }
colspan = 13
},
{
tag = 'td',
content = '',
colspan = 4
},
{
tag = 'argtd',
content = 'next',
fn = formatNext,
colspan = 13
}
}
)
})


local categories = ""
if mw.title.getCurrentTitle().namespace == 0 then
categories = "[[Category:Tournaments]]" .. infobox:getCategories()
end


return infobox:tostring()
return infobox:tostring() .. categories
end
end



Latest revision as of 15:33, 19 October 2022

To generate {{Infobox tournament}}, invoke using the main function.


--------------------------
-- Module for [[Template:Infobox tournament]]
------------------------
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 formatPrevious(previousTourney)
	if previousTourney and previousTourney ~= '' then
		return string.format('🡰 [[%s]]', previousTourney)
	end
	
	return ' '
end

local function formatNext(nextTourney)
	if nextTourney and nextTourney ~= '' then
		return string.format('[[%s]] 🡲', nextTourney)
	end
	
	return ' '
end


function p.main(frame)
	local args = getArgs(frame)
	local infobox = InfoboxBuilder.new();

	infobox:setName('Infobox tournament')
		:setParams{
			{ name = 'tournament name', default = mw.title.getCurrentTitle().text },
			{ name = 'image' },
			{ name = 'japanese' },
			{ name = 'romaji' },
			{ name = 'organizers', fn = ProcessingFns.stringToArray(',') },
			{ name = 'sponsors', fn = ProcessingFns.stringToArray(',') },
			{ name = 'prize pool' },
			{ name = 'teams' },
			{ name = 'previous', default = '' },
			{ name = 'next', default = '' }
		}
		:setArgs(args)
		:processArgs()
		
	infobox
		:addHeader({ tag = 'argth', content = 'tournament name' })
		:addImage({
			{ tag = 'argtd', content = 'image', fn = DisplayFns.image('220px') },
		})
		:addRow(
			{
				{ tag = 'th', content = 'Japanese' },
				{ tag = 'argtd', content = 'japanese' }
			},
			{ hideIfEmpty = { 'japanese' } }
		)
		:addRow(
			{
				{ tag = 'th', content = 'Romaji' },
				{ tag = 'argtd', content = 'romaji' }
			},
			{ hideIfEmpty = { 'romaji' } }
		)
		:addHeader({ tag = 'th', content = 'Tournament Information' }, { subheader = true })
		:addRow({
			{
				tag = 'argth', 
				content = 'organizers', 
				fn = DisplayFns.pluralHeader({ 'Organizer', 'Organizers' }) 
			},
			{ 
				tag = 'argtd',
				content = 'organizers', 
				fn = DisplayFns.list('unbulleted')
			}
		})
		:addRow(
			{
				{ 
					tag = 'argth', 
					content = 'sponsors',
					fn = DisplayFns.pluralHeader({ 'Sponsor', 'Sponsors' })
				},
				{ 
					tag = 'argtd', 
					content = 'sponsors',
					fn = DisplayFns.list('unbulleted')
				}
			},
			{ hideIfEmpty = { 'sponsors' } }
		)
		:addHeader({ tag = 'th', content = 'Chronology' }, { subheader = true })
		:addRow({
			{
				tag = 'argtd',
				content = 'previous',
				fn = formatPrevious,
				colspan = 13
			},
			{ 
				tag = 'td',
				content = '', 
				colspan = 4
			},
			{ 
				tag = 'argtd', 
				content = 'next',
				fn = formatNext,
				colspan = 13
			}
		})

	local categories = ""
	if mw.title.getCurrentTitle().namespace == 0 then
		categories = "[[Category:Tournaments]]" .. infobox:getCategories()
	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.