Content added Content deleted
mNo edit summary Tag: Manual revert |
(added source row) |
||
Line 15: | Line 15: | ||
end |
end |
||
local function |
local function formatSplit(val) |
||
if |
if val then |
||
local split_vals = utils.split(val, ",") |
|||
for i,v in ipairs( |
for i,v in ipairs(split_vals) do |
||
split_vals[i] = utils.trim(v) |
|||
end |
end |
||
return table.concat( |
return table.concat(split_vals, "<br>") |
||
end |
end |
||
Line 64: | Line 64: | ||
{ name = 'romaji' }, |
{ name = 'romaji' }, |
||
{ name = 'chapters' }, |
{ name = 'chapters' }, |
||
⚫ | |||
{ name = 'units', func = formatUnit }, |
{ name = 'units', func = formatUnit }, |
||
{ name = 'characters', func = formatCharacters }, |
{ name = 'characters', func = formatCharacters }, |
||
⚫ | |||
{ name = 'sources', func = formatSplit } |
|||
} |
} |
||
:setArgs(args) |
:setArgs(args) |
||
Line 91: | Line 92: | ||
{ tag = 'th', content = 'Chapters', colspan = 12 }, |
{ tag = 'th', content = 'Chapters', colspan = 12 }, |
||
{ tag = 'argtd', content = 'chapters', colspan = 18 } |
{ tag = 'argtd', content = 'chapters', colspan = 18 } |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
}) |
}) |
||
:addRow({ |
:addRow({ |
||
Line 103: | Line 100: | ||
{ tag = 'th', content = 'Characters', colspan = 12 }, |
{ tag = 'th', content = 'Characters', colspan = 12 }, |
||
{ tag = 'argtd', content = 'characters', colspan = 18 } |
{ tag = 'argtd', content = 'characters', colspan = 18 } |
||
⚫ | |||
:addHeader({ tag = 'th', content = 'Translation Information' }, { subheader = true }) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
}) |
|||
:addRow({ |
|||
{ tag = 'th', content = 'Sources', colspan = 12 }, |
|||
{ tag = 'argtd', content = 'sources', colspan = 18 } |
|||
}) |
}) |
||
Revision as of 21:45, 15 August 2021
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')
local constants = require('Module:Constants')
local utils = require('Module:Utilities')
local icons = require('Module:Icons')._main
local p = {}
local function formatImage(image_name)
return string.format("[[File:%s|220px]]", image_name)
end
local function formatSplit(val)
if val then
local split_vals = utils.split(val, ",")
for i,v in ipairs(split_vals) do
split_vals[i] = utils.trim(v)
end
return table.concat(split_vals, "<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 = {}
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')
:setWidth("330px")
:setParams{
{ name = 'story name', default = mw.title.getCurrentTitle().text },
{ name = 'image', func = formatImage },
{ name = 'japanese' },
{ name = 'romaji' },
{ name = 'chapters' },
{ name = 'units', func = formatUnit },
{ name = 'characters', func = formatCharacters },
{ name = 'translators', func = formatSplit },
{ name = 'sources', func = formatSplit }
}
:setArgs(args)
:setHeaderColors({
['background-color'] = '#00cdba',
['color'] = '#000'
})
infobox
:addHeader({ tag = 'argth', content = 'story name' })
:addImage({
{ tag = 'argtd', content = 'image' },
})
: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 }
})
:addHeader({ tag = 'th', content = 'Story Information' }, { subheader = true })
:addRow({
{ tag = 'th', content = 'Chapters', colspan = 12 },
{ tag = 'argtd', content = 'chapters', colspan = 18 }
})
:addRow({
{ tag = 'th', content = 'Units', colspan = 12 },
{ tag = 'argtd', content = 'units', colspan = 18 }
})
:addRow({
{ tag = 'th', content = 'Characters', colspan = 12 },
{ tag = 'argtd', content = 'characters', colspan = 18 }
})
:addHeader({ tag = 'th', content = 'Translation Information' }, { subheader = true })
:addRow({
{ tag = 'th', content = 'Translators', colspan = 12 },
{ tag = 'argtd', content = 'translators', colspan = 18 }
})
:addRow({
{ tag = 'th', content = 'Sources', colspan = 12 },
{ tag = 'argtd', content = 'sources', colspan = 18 }
})
return infobox:tostring()
end
return p