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

Module:Infobox album: Difference between revisions

From Sekaipedia
Content added Content deleted
mNo edit summary
mNo edit summary
Line 62: Line 62:
:setWidth("330px")
:setWidth("330px")
:setParams{
:setParams{
{ name = 'type' },
{ name = 'album id' },
{ name = 'album id' },
{ name = 'album name', default = mw.title.getCurrentTitle().text },
{ name = 'album name', default = mw.title.getCurrentTitle().text },
Line 148: Line 149:
local procArgs = infobox:getArgs('processed')
local procArgs = infobox:getArgs('processed')
local rawArgs = infobox:getArgs('raw')
local rawArgs = infobox:getArgs('raw')
if rawArgs['type'] then
if rawArgs['status'] == 'Single' then
categories = categories .. '[[Category:Singles]]'
elseif rawArgs['status'] == 'Album' then
categories = categories .. '[[Category:Albums]]'
end
end


end
end



Revision as of 06:11, 17 October 2021

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


--------------------------
-- Module for [[Template:Infobox Album]]
------------------------
local yesno     = require('Module:Yesno')
local builder   = require('Module:InfoboxBuilder')
local constants = require('Module:Constants')
local utils     = require('Module:Utilities')

local p = {}
local categories = ""

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

local function formatUnit(unit_name)
	local unit = constants.get_unit(unit_name)
	local unit_image = constants.get_unit_image(unit)
	
	if unit and unit_image then
		return string.format(
			"[[File:%s|150px|link=%s]]",
			unit_image,
			unit
		)
	end
	
	return nil
end

local function formatUnits(units)
	if units then
		local split_units = mw.text.split(units, ',')
		for i,v in ipairs(split_units) do
			split_units[i] = constants.get_unit(mw.text.trim(v))
		end
		
		return table.concat(split_units, "<br>") 
	end
	
	return nil
end

local function formatNames(names)
	if names then
		local split_names = utils.split(names, ",")
		for i,v in ipairs(split_names) do
			split_names[i] = v:match( "^%s*(.-)%s*$" )
		end
		
		return table.concat(split_names, "<br>")
	end
	
	return nil
end

function p.main(frame)
	local args = frame:getParent().args
	local infobox = builder.new();
	
	infobox:setName('Infobox Album')
		:setWidth("330px")
		:setParams{
			{ name = 'type' },
			{ name = 'album id' },
			{ name = 'album name', default = mw.title.getCurrentTitle().text },
			{ name = 'image', func = formatImage, default = 'Dummyalbumart.png' },
			{ name = 'image alt', func = formatImage },
			{ name = 'japanese' },
			{ name = 'romaji' },
			{ name = 'english' },
			{ name = 'unit', func = formatUnit },
			{ name = 'price' },
			{ name = 'label' },
			{ name = 'product number' },
			{ name = 'date' },
		}
		:setArgs(args)
		:setHeaderColorsByParam('unit', constants.get_unit_colors)

	infobox
		:addHeader({ tag = 'argth', content = 'album name' })
		:addImage(
			{
				{ tag = 'argtd', content = 'image', title = 'Original' },
				{ tag = 'argtd', content = 'image alt', title = 'Alternate' }
			}
		)
		:addRow(
			{
				{ tag = 'th', content = 'Japanese', colspan = 12 },
				{ tag = 'argtd', content = 'japanese', colspan = 18 }
			},
			{ hideIfEmpty = { 'japanese' } }
		)
		:addRow(
			{
				{ tag = 'th', content = 'Romaji', colspan = 12 },
				{ tag = 'argtd', content = 'romaji', colspan = 18 }
			},
			{ hideIfEmpty = { 'romaji' } }
		)
		:addRow(
			{
				{ tag = 'th', content = 'English', colspan = 12 },
				{ tag = 'argtd', content = 'english', colspan = 18 }
			},
			{ hideIfEmpty = { 'english' } }
		)
		:addHeader(
			{ tag = 'th', content = 'Unit' }, 
			{ hideIfEmpty = { 'unit' }, subheader = true }
		)
		:addImage(
			{
				{ tag = 'argtd', content = 'unit' }
			},
			{ hideIfEmpty = { 'unit' } }
		)
		:addHeader({ tag = 'th', content = 'Single Information' }, { subheader = true })
		:addRow(
			{
				{ tag = 'th', content = 'Price', colspan = 12 },
				{ tag = 'argtd', content = 'price', colspan = 18 }
			}
		)
		:addRow(
			{
				{ tag = 'th', content = 'Label', colspan = 12 },
				{ tag = 'argtd', content = 'label', colspan = 18 }
			}
		)
		:addRow(
			{
				{ tag = 'th', content = 'Product Number', colspan = 12 },
				{ tag = 'argtd', content = 'product number', colspan = 18 }
			}
		)
		:addRow(
			{
				{ tag = 'th', content = 'Release Date', colspan = 12 },
				{ tag = 'argtd', content = 'date', colspan = 18 }
			}
		)
	
	if mw.title.getCurrentTitle().namespace == 0 then
		categories = "[[Category:Albums]]" .. categories
		
		local procArgs = infobox:getArgs('processed')
		local rawArgs = infobox:getArgs('raw')
		
		if rawArgs['type'] then
			if rawArgs['status'] == 'Single' then
				categories = categories .. '[[Category:Singles]]'
			elseif rawArgs['status'] == 'Album' then
				categories = categories .. '[[Category:Albums]]'
			end
		end


	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.