Content added Content deleted
(using new builder) |
(changed formatting of characters) |
||
Line 6: | Line 6: | ||
local constants = require('Module:Constants') |
local constants = require('Module:Constants') |
||
local utils = require('Module:Utilities') |
local utils = require('Module:Utilities') |
||
local |
local cicon = require('Module:Character icon')._main |
||
local p = {} |
local p = {} |
||
Line 46: | Line 46: | ||
local function formatCharacters(characters) |
local function formatCharacters(characters) |
||
local characterArr = utils.split(characters, ',') |
|||
local resArr = {} |
local resArr = {} |
||
for i,v in ipairs( |
for i,v in ipairs(characters) do |
||
table.insert(resArr, |
table.insert(resArr, cicon({ v, size = '30px' })) |
||
end |
end |
||
Line 69: | Line 68: | ||
{ name = 'chapters' }, |
{ name = 'chapters' }, |
||
{ name = 'unit', pFunc = splitStringWithDelim(';'), dFunc = formatList }, |
{ name = 'unit', pFunc = splitStringWithDelim(';'), dFunc = formatList }, |
||
{ name = 'character', pFunc = splitStringWithDelim(','),dFunc = |
{ name = 'character', pFunc = splitStringWithDelim(','),dFunc = formatCharacters }, |
||
{ name = 'translator', pFunc = splitStringWithDelim(','), dFunc = formatList }, |
{ name = 'translator', pFunc = splitStringWithDelim(','), dFunc = formatList }, |
||
{ name = 'proofreader', pFunc = splitStringWithDelim(','), dFunc = formatList }, |
{ name = 'proofreader', pFunc = splitStringWithDelim(','), dFunc = formatList }, |
Revision as of 07:09, 8 February 2022
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 builder = require('Module:InfoboxBuilder new')
local constants = require('Module:Constants')
local utils = require('Module:Utilities')
local cicon = require('Module:Character icon')._main
local p = {}
local categories = ""
local function splitStringWithDelim(delim)
return function(str)
if str == nil then
return nil
end
local list = mw.text.split(str, delim)
for i=1,#list do
list[i] = mw.text.trim(list[i])
end
return list
end
end
local function formatImage(image_name)
return string.format("[[File:%s|220px]]", image_name)
end
local function formatList(list)
if #list < 2 then
return list[1]
end
local ul = mw.html.create('ul')
for i=1,#list do
ul:tag('li')
:wikitext(list[i])
end
return tostring(ul)
end
local function formatCharacters(characters)
local resArr = {}
for i,v in ipairs(characters) do
table.insert(resArr, cicon({ v, size = '30px' }))
end
return table.concat(resArr, " ")
end
function p.main(frame)
local args = getArgs(frame)
local infobox = builder.new()
infobox:setName('Infobox story')
:setParams{
{ name = 'story name', default = mw.title.getCurrentTitle().text },
{ name = 'type', pFunc = string.lower },
{ name = 'image', dFunc = formatImage },
{ name = 'japanese' },
{ name = 'romaji' },
{ name = 'chapters' },
{ name = 'unit', pFunc = splitStringWithDelim(';'), dFunc = formatList },
{ name = 'character', pFunc = splitStringWithDelim(','),dFunc = formatCharacters },
{ name = 'translator', pFunc = splitStringWithDelim(','), dFunc = formatList },
{ name = 'proofreader', pFunc = splitStringWithDelim(','), dFunc = formatList },
{ name = 'source', pFunc = splitStringWithDelim(','), dFunc = formatList }
}
:setArgs(args)
:processArgs()
:setCategoryMap({
['type'] = {
['main'] = 'Main stories',
['event'] = 'Event stories',
},
})
infobox
:addHeader({ tag = 'argth', content = 'story name' })
:addImage({
{ tag = 'argtd', content = 'image' },
})
: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 = 'Unit(s)' },
{ tag = 'argtd', content = 'unit' }
})
:addRow({
{ tag = 'th', content = 'Character(s)' },
{ tag = 'argtd', content = 'character' }
})
:addHeader({ tag = 'th', content = 'Translation Information' }, { subheader = true })
:addRow(
{
{ tag = 'th', content = 'Translator(s)' },
{ tag = 'argtd', content = 'translator' }
},
{ hideIfEmpty = { 'translator' } }
)
:addRow(
{
{ tag = 'th', content = 'Proofreader(s)' },
{ tag = 'argtd', content = 'proofreader' }
},
{ hideIfEmpty = { 'proofreader' } }
)
:addRow({
{ tag = 'th', content = 'Source(s)' },
{ tag = 'argtd', content = 'source' }
})
if mw.title.getCurrentTitle().namespace == 0 then
categories = "[[Category:Stories]]" .. infobox:getCategories()
end
return infobox:tostring() .. categories
end
return p