Module:Graphic novel list
Appearance
| This module is rated as beta. It is considered ready for widespread use, but as it is still relatively new, it should be applied with some caution to ensure results are as expected. |
| This module is currently protected from editing. See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected. |
Implements {{Graphic novel list}} and {{Graphic novel list/header}}.
Usage
{{Graphic novel list/header}}: {{#invoke:Graphic novel list|header}}
{{Graphic novel list}}: {{#invoke:Graphic novel list|row}}
local p = {}
local getArgs = require('Module:Arguments').getArgs
local function notBlank(v)
return (v or '') ~= ''
end
local function firstNotBlank(...)
for i = 1, select('#', ...) do
local v = select(i, ...)
if notBlank(v) then
return v
end
end
end
local function eq(a, b)
return notBlank(a) and a == b
end
local function isbn(frame, code)
return frame:expandTemplate{
title = 'ISBNT',
args = { code }
}
end
function p._header(args)
local out = setmetatable({}, {
__call = function(t, s) table.insert(t, s) end
})
local width = firstNotBlank(args.Width, args.width)
out('{|class="wikitable" style="width:' .. firstNotBlank(width, '100%') .. ';')
if not notBlank(width) then
out('margin:auto;')
end
if not (notBlank(width) or notBlank(args.Clear)) then
out('clear:both;')
end
out('"')
if notBlank(args.Caption) then
out('|+ ' .. args.Caption)
end
out('|-style="border-bottom:3px solid #' .. (args.LineColor or 'CCF') .. '"')
out('!width=4%|<abbr title="Number">No.</abbr>')
local withTitle = args.WithTitle == 'yes'
if withTitle then
out('!width=48%|Title')
end
if args.OneLanguage == 'yes' then
out('!width=' .. (withTitle and 24 or 48) .. '%|' .. (notBlank(args.Language) and (args.Language .. ' r') or 'R') .. 'elease date')
out('!width=' .. (withTitle and 24 or 48) .. '%|' .. (args.Language or '') .. ' ISBN')
else -- two languages
out('!width=24%|Original release date')
if not withTitle then
out('!width=24%|Original ISBN')
end
out('!width=24%|' .. firstNotBlank(args.SecondLanguage, 'English') .. ' release date')
if not withTitle then
out('!width=24%|' .. firstNotBlank(args.SecondLanguage, 'English') .. ' ISBN')
end
end
if notBlank(args[1]) or notBlank(args.episodes) then
out('<nowiki />')
out(args[1] or '')
out(args.episodes or '')
end
return table.concat(out, '|}\n')
end
function p.header(frame)
return p._header(getArgs(frame))
end
function p._row(args, frame)
if frame == nil then
frame = mw.getCurrentFrame()
end
local out = setmetatable({}, {
__call = function(t, s) table.insert(t, s) end
})
out('<tr style="text-align:center;">')
out(
string.format(
'<th scope="row" id="%svol%s" style="text-align:center;font-weight:normal;background-color:transparent;color:var(--color-base);">%s</th>',
args.Series or '',
args.VolumeNumber or '',
args.VolumeNumber or ''
)
)
-- Title --
local hasTitle =
notBlank(args.LicensedTitle)
or notBlank(args.TranslitTitle)
or notBlank(args.OriginalTitle)
or notBlank(args.Title)
if hasTitle then
out('<td style="text-align:left;">')
if notBlank(args.LicensedTitle) or notBlank(args.Title) then
out('<i>' .. (firstNotBlank(args.LicensedTitle, args.Title) or '') .. '</i>')
if notBlank(args.TranslitTitle) or notBlank(args.OriginalTitle) then
out('<br/>')
end
end
if notBlank(args.TranslitTitle) then
out('<i>' .. args.TranslitTitle .. '</i>')
if notBlank(args.OriginalTitle) then
out(' (' .. args.OriginalTitle .. ')')
end
elseif notBlank(args.OriginalTitle) then
out(args.OriginalTitle)
end
out('</td>')
else
out('<td>')
out(firstNotBlank(args.OriginalRelDate, args.RelDate) or '—')
out('</td>')
end
-- Release/ISBN slot 1 --
local relDate = firstNotBlank(args.OriginalRelDate, args.RelDate)
local ISBNcode = firstNotBlank(args.OriginalISBN, args.ISBN)
local hasLicensed = notBlank(args.LicensedRelDate) or notBlank(args.LicensedISBN)
local function renderISBN(code, note, alt)
return notBlank(code) and (isbn(frame, code) .. (notBlank(note) and (' ' .. note) or '')) or (alt or '—')
end
out('<td>')
if hasTitle then
if notBlank(relDate) or notBlank(ISBNcode) then
if eq(relDate, ISBNcode) then
out(relDate)
else
if notBlank(relDate) then
out(relDate)
if hasLicensed and notBlank(ISBNcode) then
out('<br/>')
end
end
if hasLicensed then
out(renderISBN(ISBNcode, args.ISBN_note, ''))
elseif not notBlank(relDate) then
out('—')
end
end
else
out('—')
end
else
out(renderISBN(ISBNcode, args.ISBN_note))
end
out('</td>')
-- Release/ISBN slot 2 --
if hasTitle then
out('<td>')
if hasLicensed then
if eq(args.LicensedRelDate, args.LicensedISBN) then
out(args.LicensedRelDate)
else
if notBlank(args.LicensedRelDate) then
out(args.LicensedRelDate)
if notBlank(args.LicensedISBN) then
out('<br/>')
end
end
out(renderISBN(args.LicensedISBN, args.LicensedISBN_note, ''))
end
else
out(renderISBN(firstNotBlank(args.OriginalISBN, args.ISBN), args.ISBN_note))
end
out('</td>')
elseif hasLicensed then
out('<td>' .. firstNotBlank(args.LicensedRelDate, '—') .. '</td>')
out('<td>' .. renderISBN(args.LicensedISBN, args.LicensedISBN_note) .. '</td>')
end
out('</tr>')
-- chapter list/summary --
if args.SublistOf ~= mw.title.getCurrentTitle().text then
local colspan =
hasTitle and 4
or hasLicensed and 5
or 3
if notBlank(args.ChapterListCol1) or notBlank(args.ChapterList) then
out(
string.format(
'<tr style="vertical-align:top;%s"><td colspan="%d"><table border="0" cellspacing="0" cellpadding="0" style="width:100%%;background-color:transparent;color:var(--color-base);table-layout:fixed;text-align:left;"><tr style="vertical-align:top;"><caption>%s</caption><td style="border:black;">\n',
notBlank(args.Summary) and '' or 'border-bottom:3px solid #' .. (args.LineColor or 'CCF') .. ';',
colspan,
args.Caption or ''
)
)
out(firstNotBlank(args.ChapterListCol1, args.ChapterList) or '')
if notBlank(args.ChapterListCol2) then
out('</td>\n<td style="border:black;width:48%;">\n' .. args.ChapterListCol2)
end
out('</td></tr></table>\n</td></tr>')
end
if notBlank(args.Summary) then
out(
string.format(
'<tr style="border-bottom:3px solid #%s;text-align:left;"><td colspan="%d">%s</td></tr>',
args.LineColor or 'CCF',
colspan,
args.Summary
)
)
end
end
return table.concat(out)
end
function p.row(frame)
return p._row(getArgs(frame), frame)
end
function p.footer()
return '</table>'
end
return p