Content added Content deleted
m (make translator and proofreader hidden if empty) |
(using new builder) |
||
Line 3: | Line 3: | ||
------------------------ |
------------------------ |
||
local getArgs = require('Module:Arguments').getArgs |
local getArgs = require('Module:Arguments').getArgs |
||
local builder = require('Module:InfoboxBuilder') |
local builder = require('Module:InfoboxBuilder new') |
||
local constants = require('Module:Constants') |
local constants = require('Module:Constants') |
||
local utils = require('Module:Utilities') |
local utils = require('Module:Utilities') |
||
Line 10: | Line 10: | ||
local p = {} |
local p = {} |
||
local categories = "" |
local categories = "" |
||
⚫ | |||
return function(str) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
for i=1,#list do |
|||
list[i] = mw.text.trim(list[i]) |
|||
⚫ | |||
⚫ | |||
return list |
|||
⚫ | |||
⚫ | |||
local function formatImage(image_name) |
local function formatImage(image_name) |
||
Line 15: | Line 30: | ||
end |
end |
||
local function |
local function formatList(list) |
||
if |
if #list < 2 then |
||
return list[1] |
|||
local split_vals = utils.split(val, ",") |
|||
for i,v in ipairs(split_vals) do |
|||
split_vals[i] = utils.trim(v) |
|||
⚫ | |||
⚫ | |||
return table.concat(split_vals, "<br>") |
|||
end |
end |
||
local ul = mw.html.create('ul') |
|||
⚫ | |||
⚫ | |||
for i=1,#list do |
|||
ul:tag('li') |
|||
⚫ | |||
:wikitext(list[i]) |
|||
if units and units ~= '' then |
|||
⚫ | |||
local res_list = {} |
|||
⚫ | |||
for i,v in ipairs(split_units) do |
|||
local icon = icons({ v, size = '20px' }) |
|||
⚫ | |||
table.insert(res_list, string.format( |
|||
"%s [[%s]]", |
|||
icon, |
|||
constants.get_unit(v) |
|||
⚫ | |||
end |
|||
⚫ | |||
⚫ | |||
return table.concat(res_list, '<br>') |
|||
end |
end |
||
return |
return tostring(ul) |
||
end |
end |
||
Line 59: | Line 54: | ||
return table.concat(resArr, " ") |
return table.concat(resArr, " ") |
||
end |
end |
||
Line 67: | Line 61: | ||
infobox:setName('Infobox story') |
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', pFunc = string.lower }, |
||
{ name = 'image', dFunc = formatImage }, |
|||
{ name = 'japanese' }, |
{ name = 'japanese' }, |
||
{ name = 'romaji' }, |
{ name = 'romaji' }, |
||
{ name = 'chapters' }, |
{ name = 'chapters' }, |
||
{ name = 'unit', |
{ name = 'unit', pFunc = splitStringWithDelim(';'), dFunc = formatList }, |
||
{ name = 'character', |
{ name = 'character', pFunc = splitStringWithDelim(','),dFunc = formatList }, |
||
{ name = 'translator', |
{ name = 'translator', pFunc = splitStringWithDelim(','), dFunc = formatList }, |
||
{ name = 'proofreader', |
{ name = 'proofreader', pFunc = splitStringWithDelim(','), dFunc = formatList }, |
||
{ name = 'source', |
{ name = 'source', pFunc = splitStringWithDelim(','), dFunc = formatList } |
||
} |
} |
||
:setArgs(args) |
:setArgs(args) |
||
:processArgs() |
|||
:setCategoryMap({ |
|||
⚫ | |||
['main'] = 'Main stories', |
|||
['event'] = 'Event stories', |
|||
⚫ | |||
⚫ | |||
infobox |
infobox |
||
Line 89: | Line 91: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Japanese' |
{ tag = 'th', content = 'Japanese' }, |
||
{ tag = 'argtd', content = 'japanese' |
{ tag = 'argtd', content = 'japanese' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'japanese' } } |
{ hideIfEmpty = { 'japanese' } } |
||
Line 96: | Line 98: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Romaji' |
{ tag = 'th', content = 'Romaji' }, |
||
{ tag = 'argtd', content = 'romaji' |
{ tag = 'argtd', content = 'romaji' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'romaji' } } |
{ hideIfEmpty = { 'romaji' } } |
||
Line 103: | Line 105: | ||
: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({ |
:addRow({ |
||
{ tag = 'th', content = 'Unit(s)' |
{ tag = 'th', content = 'Unit(s)' }, |
||
{ tag = 'argtd', content = 'unit' |
{ tag = 'argtd', content = 'unit' } |
||
}) |
}) |
||
:addRow({ |
:addRow({ |
||
{ tag = 'th', content = 'Character(s)' |
{ tag = 'th', content = 'Character(s)' }, |
||
{ tag = 'argtd', content = 'character' |
{ tag = 'argtd', content = 'character' } |
||
}) |
}) |
||
:addHeader({ tag = 'th', content = 'Translation Information' }, { subheader = true }) |
:addHeader({ tag = 'th', content = 'Translation Information' }, { subheader = true }) |
||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Translator(s)' |
{ tag = 'th', content = 'Translator(s)' }, |
||
{ tag = 'argtd', content = 'translator' |
{ tag = 'argtd', content = 'translator' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'translator' } } |
{ hideIfEmpty = { 'translator' } } |
||
Line 124: | Line 126: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Proofreader(s)' |
{ tag = 'th', content = 'Proofreader(s)' }, |
||
{ tag = 'argtd', content = 'proofreader' |
{ tag = 'argtd', content = 'proofreader' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'proofreader' } } |
{ hideIfEmpty = { 'proofreader' } } |
||
) |
) |
||
:addRow({ |
:addRow({ |
||
{ tag = 'th', content = 'Source(s)' |
{ tag = 'th', content = 'Source(s)' }, |
||
{ tag = 'argtd', content = 'source' |
{ tag = 'argtd', content = 'source' } |
||
}) |
}) |
||
if mw.title.getCurrentTitle().namespace == 0 then |
if mw.title.getCurrentTitle().namespace == 0 then |
||
categories = "[[Category:Stories]]" .. |
categories = "[[Category:Stories]]" .. infobox:getCategories() |
||
local procArgs = infobox:getArgs('processed') |
|||
local rawArgs = infobox:getArgs('raw') |
|||
⚫ | |||
if rawArgs['type'] == 'main' then |
|||
categories = categories .. '[[Category:Main stories]]' |
|||
elseif rawArgs['type'] == 'event' then |
|||
categories = categories .. '[[Category:Event stories]]' |
|||
elseif rawArgs['type'] == 'side' then |
|||
categories = categories .. '[[Category:Side stories]]' |
|||
end |
|||
⚫ | |||
end |
end |
||
Revision as of 07:03, 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 icons = require('Module:Icons')._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 characterArr = utils.split(characters, ',')
local resArr = {}
for i,v in ipairs(characterArr) do
table.insert(resArr, icons({ 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 = formatList },
{ 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