mNo edit summary |
m (YBamY moved page Module:Infobox Album to Module:Infobox album without leaving a redirect) |
(No difference)
|
Revision as of 01:59, 16 November 2021
This module depends on the following other modules: |
To generate {{Infobox album}}, invoke using the main function.
--------------------------
-- Module for [[Template:Infobox Album]]
------------------------
local getArgs = require('Module:Arguments').getArgs
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 formatType(type)
if val == Album then
return 'Album Information'
elseif val == Single then
return 'Single Information'
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 = getArgs(frame, { wrappers = 'Template:Infobox album' })
local infobox = builder.new()
infobox:setName('Infobox album')
:setWidth("330px")
:setParams{
{ name = 'type', func = formatType },
{ 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 = 'argth', content = 'type' }, { subheader = true })
:addRow(
{
{ tag = 'th', content = 'Price', colspan = 12 },
{ tag = 'td', content = '¥ price (before tax)', 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 and singles]]" .. categories
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
return infobox:tostring() .. categories
end
return p