Module:Infobox Episode: Difference between revisions

From Brighter Shores Wiki
Jump to navigation Jump to search
Content added Content deleted
(Manually define premium here)
(Add default sort for episodes via "sequence_number" param)
 
Line 17:
parse.release,
-- Premium manually defined in episode infoboxes
{ name = 'premium', func = parse.yes_no, smw_property = 'Premium', smw_func = parse.yes_no_smw, category_incomplete = 'Needs premium status' },
{ name = 'sequence_number', func = parse.number, smw_property = 'Episode sequence number', smw_func = parse.number, category_incomplete = 'Needs episode sequence number' },
}
 
local infobox = Infobox.new(config, params, args)
infobox
Line 37 ⟶ 38:
}
:pad(20)
 
if infobox:is_param_defined(Infobox.param('sequence_number')) > 0 then
local sequence_number = tonumber(infobox:get_param(Infobox.param('sequence_number'), 0))
if sequence_number > 10 then
error('Please change [[Module:Infobox Episode]] to pad episode number to be 2 digits long (e.g., "Episode 01: Hopeport") to preserve sorting')
end
frame:callParserFunction{ name = 'DEFAULTSORT', args = ('Episode %d: %s'):format(sequence_number, infobox:get_param(Infobox.param('name'), 0)) }
end
 
return infobox
end

Latest revision as of 15:33, 22 November 2024

Module documentation
This documentation is transcluded from Module:Infobox Episode/doc. [edit] [history] [purge]
This module does not have any documentation. Please consider adding documentation at Module:Infobox Episode/doc. [edit]
Module:Infobox Episode's function main is invoked by Template:Infobox Episode.
Module:Infobox Episode requires Module:Infobox.
Module:Infobox Episode requires Module:Param Parse.

local p = {}

local Infobox = require('Module:Infobox')
local parse = require('Module:Param Parse')

function p.main(frame)
	local args = frame:getParent().args
	
	local config = {
		infobox_name = 'Episode',
		class = {Infobox.param('name')},
	}
	
	local params = {
		parse.name,
		parse.image,
		parse.release,
		-- Premium manually defined in episode infoboxes
		{ name = 'premium',	func = parse.yes_no, smw_property = 'Premium', smw_func = parse.yes_no_smw, category_incomplete = 'Needs premium status' },
		{ name = 'sequence_number', func = parse.number, smw_property = 'Episode sequence number', smw_func = parse.number, category_incomplete = 'Needs episode sequence number' },
	}

	local infobox = Infobox.new(config, params, args)
	infobox
		:add_row{
			{tag='th', content=Infobox.param('name'), class='infobox-header', colspan='20'},
		}
		:add_row{
			{tag='td', content=Infobox.param('image'), class='infobox-image', colspan='20'},
		}
		:add_row{
			{tag='th', content='Release', colspan="6"},
			{tag='td', content=Infobox.param('release'), colspan="14"},
		}
		:add_row{
			{tag='th', content='[[Premium Pass|Premium]]', colspan="6"},
			{tag='td', content=Infobox.param('premium'), colspan="14"},
		}
		:pad(20)

	if infobox:is_param_defined(Infobox.param('sequence_number')) > 0 then
		local sequence_number = tonumber(infobox:get_param(Infobox.param('sequence_number'), 0))
		if sequence_number > 10 then
			error('Please change [[Module:Infobox Episode]] to pad episode number to be 2 digits long (e.g., "Episode 01: Hopeport") to preserve sorting')
		end
		frame:callParserFunction{ name = 'DEFAULTSORT', args = ('Episode %d: %s'):format(sequence_number, infobox:get_param(Infobox.param('name'), 0)) }
	end

	return infobox
end

return p