Content added Content deleted
Tag: Undo |
Tag: Undo |
||
Line 51: | Line 51: | ||
{ name = 'album name', default = mw.title.getCurrentTitle().text }, |
{ name = 'album name', default = mw.title.getCurrentTitle().text }, |
||
{ name = 'image', default = 'Dummyalbumart.png' }, |
{ name = 'image', default = 'Dummyalbumart.png' }, |
||
{ name = 'image alt 1'}, |
|||
{ name = 'image alt 2'}, |
|||
{ name = 'image alt 3'}, |
|||
{ name = 'image alt 4'}, |
|||
{ name = 'image alt 5'}, |
|||
{ name = 'japanese' }, |
{ name = 'japanese' }, |
||
{ name = 'romaji' }, |
{ name = 'romaji' }, |
||
Line 78: | Line 73: | ||
:addImage({ |
:addImage({ |
||
{ tag = 'argtd', content = 'image', fn = DisplayFns.image('220px') } |
{ tag = 'argtd', content = 'image', fn = DisplayFns.image('220px') } |
||
} |
}) |
||
{ |
|||
tag = 'argtd', |
|||
content = 'image alt 1', |
|||
fn = DisplayFns.image('220px'), |
|||
tabName = '{{{1}}}' |
|||
}, |
|||
{ |
|||
tag = 'argtd', |
|||
content = 'image alt 2', |
|||
fn = DisplayFns.image('220px'), |
|||
tabName = '{{{2}}}' |
|||
}, |
|||
{ |
|||
tag = 'argtd', |
|||
content = 'image alt 3', |
|||
fn = DisplayFns.image('220px'), |
|||
tabName = '{{{3}}}' |
|||
}, |
|||
{ |
|||
tag = 'argtd', |
|||
content = 'image alt 4', |
|||
fn = DisplayFns.image('220px'), |
|||
tabName = '{{{4}}}' |
|||
}, |
|||
{ |
|||
tag = 'argtd', |
|||
content = 'image alt 5', |
|||
fn = DisplayFns.image('220px'), |
|||
tabName = '{{{5}}}' |
|||
}) |
|||
:addRow( |
:addRow( |
||
{ |
{ |
Latest revision as of 22:14, 29 January 2024
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 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