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
m (corrected name for proper linking)
m (Undo revision 99319 by Rixxy (talk))
Tag: Undo
 
(25 intermediate revisions by 3 users not shown)
Line 3:
------------------------
local getArgs = require('Module:Arguments').getArgs
local yesno InfoboxBuilder = require('Module:YesnoInfoboxBuilder')
local builderDisplayFns = require('Module:InfoboxBuilderDisplayFunctions')
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)
Line 30 ⟶ 24:
end
 
local function formatAlbumformatType(albumval)
localif val == yesno(album,'Album' nil)then
-- probably should not use == with bool, but this is more explicit
if val == true then
return 'Album Information'
elseif val == false'Single' then
return 'Single Information'
end
return nil'? Information'
end
 
local function formatNamesformatPrice(namesprice)
if namesprice then
return string.format("[[File:%s|220px]]" (before tax)', image_nameprice)
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 nilprice
return nil
end
 
Line 58 ⟶ 44:
function p.main(frame)
local args = getArgs(frame, { wrappers = 'Template:Infobox album' })
local infobox = builderInfoboxBuilder.new()
infobox:setName('Infobox album')
:setWidth("330px")
:setParams{
{ name = 'albumtype', funcdefault = formatAlbum'' },
{ 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' },
Line 78 ⟶ 61:
}
:setArgs(args)
:processArgs()
:setHeaderColorsByParam('unit', constants.get_unit_colors)
:setCategoryMap({
if rawArgs ['type'] then= {
['Album'] = 'Albums',
['Single'] = 'Singles'
}
})
 
infobox
:addHeader({ tag = 'argth', content = 'album name' })
:addImage({
{ tag = 'argtd', content = 'image', titlefn = DisplayFns.image('Original220px') },
{
})
{ 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' } }
Line 97 ⟶ 83:
:addRow(
{
{ tag = 'th', content = 'Romaji', colspan = 12 },
{ tag = 'argtd', content = 'romaji', colspan = 18 }
},
{ hideIfEmpty = { 'romaji' } }
Line 104 ⟶ 90:
:addRow(
{
{ tag = 'th', content = 'English', colspan = 12 },
{ tag = 'argtd', content = 'english', colspan = 18 }
},
{ hideIfEmpty = { 'english' } }
Line 115 ⟶ 101:
:addImage(
{
{ tag = 'argtd', content = 'unit', fn = formatUnit }
},
{ hideIfEmpty = { 'unit' } }
)
:addHeader({ tag = 'argth', content = 'albumtype', fn = formatType }, { subheader = true })
:addRow(
{
{ tag = 'th', content = 'Price', colspan = 12 },
{ tag = 'argtd', content = 'price', colspanfn = 18formatPrice }
}
)
:addRow(
{
{ tag = 'th', content = 'Label', colspan = 12 },
{ tag = 'argtd', content = 'label', colspan = 18 }
}
)
:addRow(
{
{ tag = 'th', content = 'Product Numbernumber', colspan = 12 },
{ tag = 'argtd', content = 'product number', colspan = 18 }
}
)
:addRow(
{
{ tag = 'th', content = 'Release Datedate', colspan = 12 },
{ tag = 'argtd', content = 'date', colspan = 18 }
}
)
local categories = ""
if mw.title.getCurrentTitle().namespace == 0 then
categories = "[[Category:Albums and singles]]" .. categoriesinfobox:getCategories()
local procArgs = infobox:getArgs('processed')
local rawArgs = infobox:getArgs('raw')
if rawArgs['type'] then
if rawArgs['type'] == 'Single' then
categories = categories .. '[[Category:Singles]]'
elseif rawArgs['type'] == 'Album' then
categories = categories .. '[[Category:Albums]]'
end
end
 
 
end
 

Latest revision as of 22:14, 29 January 2024

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


--------------------------
-- Module for [[Template:Infobox Album]]
------------------------
local getArgs   = require('Module:Arguments').getArgs
local InfoboxBuilder = require('Module:InfoboxBuilder')
local DisplayFns     = require('Module:DisplayFunctions')
local constants = require('Module:Constants')

local p = {}

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 formatType(val)
	if val == 'Album' then
		return 'Album Information'
	elseif val == 'Single' then
		return 'Single Information'
	end
	
	return '? Information'
end

local function formatPrice(price)
	if price then
		return string.format('¥%s (before tax)', price)
	end
	return price
end


function p.main(frame)
	local args = getArgs(frame, { wrappers = 'Template:Infobox album' })
	local infobox = InfoboxBuilder.new()
	
	infobox:setName('Infobox album')
		:setParams{
			{ name = 'type', default = '' },
			{ name = 'album name', default = mw.title.getCurrentTitle().text },
			{ name = 'image', default = 'Dummyalbumart.png' },
			{ name = 'japanese' },
			{ name = 'romaji' },
			{ name = 'english' },
			{ name = 'unit' },
			{ name = 'price' },
			{ name = 'label' },
			{ name = 'product number' },
			{ name = 'date' },
		}
		:setArgs(args)
		:processArgs()
		:setCategoryMap({
			['type'] = {
				['Album']  = 'Albums',
				['Single'] = 'Singles'
			}
		})

	infobox
		:addHeader({ tag = 'argth', content = 'album 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' } }
		)
		:addRow(
			{
				{ tag = 'th', content = 'English' },
				{ tag = 'argtd', content = 'english' }
			},
			{ hideIfEmpty = { 'english' } }
		)
		:addHeader(
			{ tag = 'th', content = 'Unit' }, 
			{ hideIfEmpty = { 'unit' }, subheader = true }
		)
		:addImage(
			{
				{ tag = 'argtd', content = 'unit', fn = formatUnit }
			},
			{ hideIfEmpty = { 'unit' } }
		)
		:addHeader({ tag = 'argth', content = 'type', fn = formatType }, { subheader = true })
		:addRow(
			{
				{ tag = 'th', content = 'Price' },
				{ tag = 'argtd', content = 'price', fn = formatPrice }
			}
		)
		:addRow(
			{
				{ tag = 'th', content = 'Label' },
				{ tag = 'argtd', content = 'label' }
			}
		)
		:addRow(
			{
				{ tag = 'th', content = 'Product number' },
				{ tag = 'argtd', content = 'product number' }
			}
		)
		:addRow(
			{
				{ tag = 'th', content = 'Release date' },
				{ tag = 'argtd', content = 'date' }
			}
		)
	
	local categories = ""
	if mw.title.getCurrentTitle().namespace == 0 then
		categories = "[[Category:Albums and singles]]" .. 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.