Content added Content deleted
mNo edit summary Tag: Manual revert |
mNo edit summary |
||
(23 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
-------------------------- |
-------------------------- |
||
-- Module for [[Template:Infobox |
-- Module for [[Template:Infobox story]] |
||
------------------------ |
------------------------ |
||
local getArgs = require('Module:Arguments').getArgs |
local getArgs = require('Module:Arguments').getArgs |
||
local |
local InfoboxBuilder = require('Module:InfoboxBuilder') |
||
local DisplayFns = require('Module:DisplayFunctions') |
|||
local ProcessingFns = require('Module:ProcessingFunctions') |
|||
local constants = require('Module:Constants') |
local constants = require('Module:Constants') |
||
local |
local cicon = require('Module:Character icon')._main |
||
local icons = require('Module:Icons')._main |
|||
local p = {} |
local p = {} |
||
local function |
local function formatCharacters(characters) |
||
if characters == nil then return nil end |
|||
return string.format("[[File:%s|220px]]", image_name) |
|||
end |
|||
local function formatTranslators(translators) |
|||
if translators then |
|||
local split_translators = utils.split(translators, ",") |
|||
for i,v in ipairs(split_translators) do |
|||
split_translators[i] = utils.trim(v) |
|||
end |
|||
return table.concat(split_translators, "<br>") |
|||
end |
|||
return nil |
|||
end |
|||
local function formatUnit(unit) |
|||
if unit and unit ~= '' then |
|||
return string.format( |
|||
"%s [[%s]]", |
|||
icons({ unit, size = '20px' }), |
|||
constants.get_unit(unit) |
|||
) |
|||
end |
|||
return nil |
|||
end |
|||
local function formatCharacters(characters) |
|||
local characterArr = utils.split(characters, ',') |
|||
local resArr = {} |
local resArr = {} |
||
for |
for _, character in ipairs(characters) do |
||
table.insert(resArr, |
table.insert(resArr, cicon({ character, size = '30px' })) |
||
end |
end |
||
return table.concat(resArr, " ") |
return table.concat(resArr, " ") |
||
end |
end |
||
function p.main(frame) |
function p.main(frame) |
||
local args = getArgs(frame) |
local args = getArgs(frame) |
||
local infobox = |
local infobox = InfoboxBuilder.new() |
||
infobox:setName('Infobox |
infobox:setName('Infobox story') |
||
:setWidth("330px") |
|||
:setParams{ |
:setParams{ |
||
{ name = 'story name', default = mw.title.getCurrentTitle().text }, |
{ name = 'story name', default = mw.title.getCurrentTitle().text }, |
||
{ name = ' |
{ name = 'type', fn = string.lower }, |
||
{ name = 'image' }, |
|||
{ name = 'japanese' }, |
{ name = 'japanese' }, |
||
{ name = 'romaji' }, |
{ name = 'romaji' }, |
||
{ name = 'chapters' }, |
{ name = 'chapters' }, |
||
{ name = ' |
{ name = 'key unit', fn = ProcessingFns.stringToArray(';') }, |
||
{ name = ' |
{ name = 'involved unit', fn = ProcessingFns.stringToArray(';') }, |
||
{ name = ' |
{ name = 'character', fn = ProcessingFns.stringToArray(',') }, |
||
{ name = 'translator', fn = ProcessingFns.stringToArray(',') }, |
|||
{ name = 'proofreader', fn = ProcessingFns.stringToArray(',') }, |
|||
{ name = 'source', fn = ProcessingFns.stringToArray(',') } |
|||
} |
} |
||
:setArgs(args) |
:setArgs(args) |
||
:processArgs() |
|||
:setHeaderColors({ |
|||
:setCategoryMap({ |
|||
['background-color'] = '#00cdba', |
|||
[' |
['type'] = { |
||
['main'] = 'Main Stories', |
|||
['event'] = 'Event stories', |
|||
['special'] = 'Special Stories', |
|||
}, |
|||
}) |
}) |
||
Line 77: | Line 55: | ||
:addHeader({ tag = 'argth', content = 'story name' }) |
:addHeader({ tag = 'argth', content = 'story name' }) |
||
:addImage({ |
:addImage({ |
||
{ tag = 'argtd', content = 'image' }, |
{ tag = 'argtd', content = 'image', fn = DisplayFns.image('220px') }, |
||
}) |
|||
:addRow({ |
|||
{ tag = 'th', content = 'Japanese', colspan = 12 }, |
|||
{ tag = 'argtd', content = 'japanese', colspan = 18 } |
|||
}) |
|||
:addRow({ |
|||
{ tag = 'th', content = 'Romaji', colspan = 12 }, |
|||
{ tag = 'argtd', content = 'romaji', colspan = 18 } |
|||
}) |
}) |
||
:addRow( |
|||
{ |
|||
{ tag = 'th', content = 'Japanese' }, |
|||
{ tag = 'argtd', content = 'japanese' } |
|||
}, |
|||
{ hideIfEmpty = { 'japanese' } } |
|||
) |
|||
:addRow( |
|||
{ |
|||
{ tag = 'th', content = 'Romaji' }, |
|||
{ tag = 'argtd', content = 'romaji' } |
|||
}, |
|||
{ hideIfEmpty = { 'romaji' } } |
|||
) |
|||
:addHeader({ tag = 'th', content = 'Story Information' }, { subheader = true }) |
:addHeader({ tag = 'th', content = 'Story Information' }, { subheader = true }) |
||
:addRow({ |
:addRow({ |
||
{ tag = 'th', content = 'Chapters' |
{ tag = 'th', content = 'Chapters' }, |
||
{ tag = 'argtd', content = 'chapters' |
{ tag = 'argtd', content = 'chapters' } |
||
}) |
}) |
||
:addRow( |
|||
{ |
|||
{ tag = 'th', content = 'Key unit' }, |
|||
{ |
|||
tag = 'argtd', |
|||
content = 'key unit', |
|||
fn = DisplayFns.list('unbulleted') |
|||
} |
|||
}, |
|||
{ hideIfEmpty = { 'key unit' } } |
|||
) |
|||
:addRow( |
|||
{ |
|||
{ |
|||
tag = 'argth', |
|||
content = 'involved unit', |
|||
fn = DisplayFns.pluralHeader({ 'Unit involved', 'Units involved' }) |
|||
}, |
|||
{ |
|||
tag = 'argtd', |
|||
content = 'involved unit', |
|||
fn = DisplayFns.list('unbulleted') |
|||
} |
|||
}, |
|||
{ hideIfEmpty = { 'involved unit' } } |
|||
) |
|||
:addRow({ |
:addRow({ |
||
{ |
|||
{ tag = 'th', content = 'Translators', colspan = 12 }, |
|||
tag = 'argth', |
|||
content = 'character', |
|||
fn = DisplayFns.pluralHeader({ 'Character', 'Characters' }) |
|||
}, |
|||
{ |
|||
tag = 'argtd', |
|||
content = 'character', |
|||
fn = formatCharacters |
|||
} |
|||
}) |
}) |
||
:addHeader({ tag = 'th', content = 'Translation Information' }, { subheader = true }) |
|||
:addRow( |
|||
{ |
|||
{ |
|||
tag = 'argth', |
|||
content = 'translator', |
|||
fn = DisplayFns.pluralHeader({ 'Translator', 'Translators' }) |
|||
}, |
|||
{ |
|||
tag = 'argtd', |
|||
content = 'translator', |
|||
fn = DisplayFns.list('unbulleted') |
|||
} |
|||
}, |
|||
{ hideIfEmpty = { 'translator' } } |
|||
) |
|||
:addRow( |
|||
{ |
|||
{ |
|||
tag = 'argth', |
|||
content = 'proofreader', |
|||
fn = DisplayFns.pluralHeader({ 'Proofreader', 'Proofreaders' }) |
|||
}, |
|||
{ |
|||
tag = 'argtd', |
|||
content = 'proofreader', |
|||
fn = DisplayFns.list('unbulleted') |
|||
} |
|||
}, |
|||
{ hideIfEmpty = { 'proofreader' } } |
|||
) |
|||
:addRow({ |
:addRow({ |
||
{ |
|||
{ tag = 'th', content = 'Units', colspan = 12 }, |
|||
tag = 'argth', |
|||
content = 'source', |
|||
}) |
|||
fn = DisplayFns.pluralHeader({ 'Source', 'Sources' }) |
|||
:addRow({ |
|||
}, |
|||
{ tag = 'th', content = 'Characters', colspan = 12 }, |
|||
{ |
|||
{ tag = 'argtd', content = 'characters', colspan = 18 } |
|||
tag = 'argtd', |
|||
content = 'source', |
|||
fn = DisplayFns.list('unbulleted') |
|||
} |
|||
}) |
}) |
||
local categories = "" |
|||
if mw.title.getCurrentTitle().namespace == 0 then |
|||
categories = "[[Category:Stories]]" .. infobox:getCategories() |
|||
end |
|||
return infobox:tostring() |
return infobox:tostring() .. categories |
||
end |
end |
||
Latest revision as of 15:46, 28 December 2023
This module depends on the following other modules: |
To generate {{Infobox story}}, invoke using the main function.
--------------------------
-- Module for [[Template:Infobox story]]
------------------------
local getArgs = require('Module:Arguments').getArgs
local InfoboxBuilder = require('Module:InfoboxBuilder')
local DisplayFns = require('Module:DisplayFunctions')
local ProcessingFns = require('Module:ProcessingFunctions')
local constants = require('Module:Constants')
local cicon = require('Module:Character icon')._main
local p = {}
local function formatCharacters(characters)
if characters == nil then return nil end
local resArr = {}
for _, character in ipairs(characters) do
table.insert(resArr, cicon({ character, size = '30px' }))
end
return table.concat(resArr, " ")
end
function p.main(frame)
local args = getArgs(frame)
local infobox = InfoboxBuilder.new()
infobox:setName('Infobox story')
:setParams{
{ name = 'story name', default = mw.title.getCurrentTitle().text },
{ name = 'type', fn = string.lower },
{ name = 'image' },
{ name = 'japanese' },
{ name = 'romaji' },
{ name = 'chapters' },
{ name = 'key unit', fn = ProcessingFns.stringToArray(';') },
{ name = 'involved unit', fn = ProcessingFns.stringToArray(';') },
{ name = 'character', fn = ProcessingFns.stringToArray(',') },
{ name = 'translator', fn = ProcessingFns.stringToArray(',') },
{ name = 'proofreader', fn = ProcessingFns.stringToArray(',') },
{ name = 'source', fn = ProcessingFns.stringToArray(',') }
}
:setArgs(args)
:processArgs()
:setCategoryMap({
['type'] = {
['main'] = 'Main Stories',
['event'] = 'Event stories',
['special'] = 'Special Stories',
},
})
infobox
:addHeader({ tag = 'argth', content = 'story 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' } }
)
:addHeader({ tag = 'th', content = 'Story Information' }, { subheader = true })
:addRow({
{ tag = 'th', content = 'Chapters' },
{ tag = 'argtd', content = 'chapters' }
})
:addRow(
{
{ tag = 'th', content = 'Key unit' },
{
tag = 'argtd',
content = 'key unit',
fn = DisplayFns.list('unbulleted')
}
},
{ hideIfEmpty = { 'key unit' } }
)
:addRow(
{
{
tag = 'argth',
content = 'involved unit',
fn = DisplayFns.pluralHeader({ 'Unit involved', 'Units involved' })
},
{
tag = 'argtd',
content = 'involved unit',
fn = DisplayFns.list('unbulleted')
}
},
{ hideIfEmpty = { 'involved unit' } }
)
:addRow({
{
tag = 'argth',
content = 'character',
fn = DisplayFns.pluralHeader({ 'Character', 'Characters' })
},
{
tag = 'argtd',
content = 'character',
fn = formatCharacters
}
})
:addHeader({ tag = 'th', content = 'Translation Information' }, { subheader = true })
:addRow(
{
{
tag = 'argth',
content = 'translator',
fn = DisplayFns.pluralHeader({ 'Translator', 'Translators' })
},
{
tag = 'argtd',
content = 'translator',
fn = DisplayFns.list('unbulleted')
}
},
{ hideIfEmpty = { 'translator' } }
)
:addRow(
{
{
tag = 'argth',
content = 'proofreader',
fn = DisplayFns.pluralHeader({ 'Proofreader', 'Proofreaders' })
},
{
tag = 'argtd',
content = 'proofreader',
fn = DisplayFns.list('unbulleted')
}
},
{ hideIfEmpty = { 'proofreader' } }
)
:addRow({
{
tag = 'argth',
content = 'source',
fn = DisplayFns.pluralHeader({ 'Source', 'Sources' })
},
{
tag = 'argtd',
content = 'source',
fn = DisplayFns.list('unbulleted')
}
})
local categories = ""
if mw.title.getCurrentTitle().namespace == 0 then
categories = "[[Category:Stories]]" .. infobox:getCategories()
end
return infobox:tostring() .. categories
end
return p