Content added Content deleted
m (added delim) Tag: Reverted |
mNo edit summary Tag: Reverted |
||
Line 11: | Line 11: | ||
local function formatImage(imageName) |
local function formatImage(imageName) |
||
return string.format("[[File:%s|220px]]", imageName) |
return string.format("[[File:%s|220px]]", imageName) |
||
end |
|||
local function formatList(list) |
|||
if #list < 2 then |
|||
return list[1] |
|||
end |
|||
local br = mw.html.create('<br>') |
|||
for i=1,#list do |
|||
br:tag('li') |
|||
:wikitext(list[i]) |
|||
end |
|||
return tostring(br) |
|||
end |
end |
||
Revision as of 07:52, 25 June 2022
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 new')
local constants = require('Module:Constants')
local utils = require('Module:Utilities')
local p = {}
local function formatImage(imageName)
return string.format("[[File:%s|220px]]", imageName)
end
local function formatList(list)
if #list < 2 then
return list[1]
end
local br = mw.html.create('<br>')
for i=1,#list do
br:tag('li')
:wikitext(list[i])
end
return tostring(br)
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(val)
if val == 'Album' then
return 'Album Information'
elseif val == 'Single' then
return 'Single Information'
end
return '? Information'
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
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 = builder.new()
infobox:setName('Infobox album')
:setParams{
{ name = 'type', dFunc = formatType, default = '' },
{ name = 'album name', default = mw.title.getCurrentTitle().text },
{ name = 'image', dFunc = formatImage, default = 'Dummyalbumart.png' },
{ name = 'japanese' },
{ name = 'romaji' },
{ name = 'english' },
{ name = 'unit', dFunc = formatUnit },
{ name = 'price', dFunc = formatPrice },
{ name = 'label' },
{ name = 'product number', pFunc = utils.splitWithDelim(';') },
{ name = 'date' },
}
:setArgs(args)
:processArgs()
:setCategoryMap({
['type'] = {
['Album'] = 'Albums',
['Single'] = 'Singles'
}
})
infobox
:addHeader({ tag = 'argth', content = 'album name' })
:addImage(
{
{ tag = 'argtd', content = 'image', title = 'Original' }
}
)
: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' }
},
{ hideIfEmpty = { 'unit' } }
)
:addHeader({ tag = 'argth', content = 'type' }, { subheader = true })
:addRow(
{
{ tag = 'th', content = 'Price' },
{ tag = 'argtd', content = 'price' }
}
)
: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