Content added Content deleted
m (corrected name for proper linking) |
Tag: Undo |
||
(25 intermediate revisions by 3 users not shown) | |||
Line 3: | Line 3: | ||
------------------------ |
------------------------ |
||
local getArgs = require('Module:Arguments').getArgs |
local getArgs = require('Module:Arguments').getArgs |
||
local |
local InfoboxBuilder = require('Module:InfoboxBuilder') |
||
local |
local DisplayFns = require('Module:DisplayFunctions') |
||
local constants = require('Module:Constants') |
local constants = require('Module:Constants') |
||
local utils = require('Module:Utilities') |
|||
local p = {} |
local p = {} |
||
⚫ | |||
local function formatImage(image_name) |
|||
⚫ | |||
end |
|||
local function formatUnit(unit_name) |
local function formatUnit(unit_name) |
||
Line 30: | Line 24: | ||
end |
end |
||
local function |
local function formatType(val) |
||
if val == 'Album' then |
|||
-- probably should not use == with bool, but this is more explicit |
|||
if val == true then |
|||
return 'Album Information' |
return 'Album Information' |
||
elseif val == |
elseif val == 'Single' then |
||
return 'Single Information' |
return 'Single Information' |
||
end |
end |
||
return |
return '? Information' |
||
end |
end |
||
local function |
local function formatPrice(price) |
||
if |
if price 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 |
end |
||
⚫ | |||
⚫ | |||
end |
end |
||
Line 58: | Line 44: | ||
function p.main(frame) |
function p.main(frame) |
||
local args = getArgs(frame, { wrappers = 'Template:Infobox album' }) |
local args = getArgs(frame, { wrappers = 'Template:Infobox album' }) |
||
local infobox = |
local infobox = InfoboxBuilder.new() |
||
infobox:setName('Infobox album') |
infobox:setName('Infobox album') |
||
:setWidth("330px") |
|||
:setParams{ |
:setParams{ |
||
{ name = ' |
{ name = 'type', default = '' }, |
||
{ name = 'album id' }, |
|||
{ name = 'album name', default = mw.title.getCurrentTitle().text }, |
{ name = 'album name', default = mw.title.getCurrentTitle().text }, |
||
{ name = 'image' |
{ name = 'image', default = 'Dummyalbumart.png' }, |
||
{ name = 'image alt', func = formatImage }, |
|||
{ name = 'japanese' }, |
{ name = 'japanese' }, |
||
{ name = 'romaji' }, |
{ name = 'romaji' }, |
||
{ name = 'english' }, |
{ name = 'english' }, |
||
{ name = 'unit' |
{ name = 'unit' }, |
||
{ name = 'price' }, |
{ name = 'price' }, |
||
{ name = 'label' }, |
{ name = 'label' }, |
||
Line 78: | Line 61: | ||
} |
} |
||
:setArgs(args) |
:setArgs(args) |
||
:processArgs() |
|||
:setHeaderColorsByParam('unit', constants.get_unit_colors) |
|||
:setCategoryMap({ |
|||
⚫ | |||
['Album'] = 'Albums', |
|||
['Single'] = 'Singles' |
|||
⚫ | |||
⚫ | |||
infobox |
infobox |
||
:addHeader({ tag = 'argth', content = 'album name' }) |
:addHeader({ tag = 'argth', content = 'album name' }) |
||
:addImage( |
:addImage({ |
||
⚫ | |||
{ |
|||
⚫ | |||
⚫ | |||
{ tag = 'argtd', content = 'image alt', title = 'Alternate' } |
|||
⚫ | |||
⚫ | |||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Japanese' |
{ tag = 'th', content = 'Japanese' }, |
||
{ tag = 'argtd', content = 'japanese' |
{ tag = 'argtd', content = 'japanese' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'japanese' } } |
{ hideIfEmpty = { 'japanese' } } |
||
Line 97: | Line 83: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Romaji' |
{ tag = 'th', content = 'Romaji' }, |
||
{ tag = 'argtd', content = 'romaji' |
{ tag = 'argtd', content = 'romaji' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'romaji' } } |
{ hideIfEmpty = { 'romaji' } } |
||
Line 104: | Line 90: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'English' |
{ tag = 'th', content = 'English' }, |
||
{ tag = 'argtd', content = 'english' |
{ tag = 'argtd', content = 'english' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'english' } } |
{ hideIfEmpty = { 'english' } } |
||
Line 115: | Line 101: | ||
:addImage( |
:addImage( |
||
{ |
{ |
||
{ tag = 'argtd', content = 'unit' } |
{ tag = 'argtd', content = 'unit', fn = formatUnit } |
||
}, |
}, |
||
{ hideIfEmpty = { 'unit' } } |
{ hideIfEmpty = { 'unit' } } |
||
) |
) |
||
:addHeader({ tag = 'argth', content = ' |
:addHeader({ tag = 'argth', content = 'type', fn = formatType }, { subheader = true }) |
||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Price' |
{ tag = 'th', content = 'Price' }, |
||
{ tag = 'argtd', content = 'price', |
{ tag = 'argtd', content = 'price', fn = formatPrice } |
||
} |
} |
||
) |
) |
||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Label' |
{ tag = 'th', content = 'Label' }, |
||
{ tag = 'argtd', content = 'label' |
{ tag = 'argtd', content = 'label' } |
||
} |
} |
||
) |
) |
||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Product |
{ tag = 'th', content = 'Product number' }, |
||
{ tag = 'argtd', content = 'product number' |
{ tag = 'argtd', content = 'product number' } |
||
} |
} |
||
) |
) |
||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Release |
{ tag = 'th', content = 'Release date' }, |
||
{ tag = 'argtd', content = 'date' |
{ tag = 'argtd', content = 'date' } |
||
} |
} |
||
) |
) |
||
⚫ | |||
if mw.title.getCurrentTitle().namespace == 0 then |
if mw.title.getCurrentTitle().namespace == 0 then |
||
categories = "[[Category:Albums and singles]]" .. |
categories = "[[Category:Albums and singles]]" .. infobox:getCategories() |
||
local procArgs = infobox:getArgs('processed') |
|||
local rawArgs = infobox:getArgs('raw') |
|||
⚫ | |||
if rawArgs['type'] == 'Single' then |
|||
categories = categories .. '[[Category:Singles]]' |
|||
elseif rawArgs['type'] == 'Album' then |
|||
categories = categories .. '[[Category:Albums]]' |
|||
end |
|||
end |
|||
end |
end |
||
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