Content added Content deleted
(created infobox story) |
(added formatting for unit and characters) |
||
Line 4: | Line 4: | ||
local getArgs = require('Module:Arguments').getArgs |
local getArgs = require('Module:Arguments').getArgs |
||
local builder = require('Module:InfoboxBuilder') |
local builder = require('Module:InfoboxBuilder') |
||
local constants = require('Module:Constants') |
|||
local utils = require('Module:Utilities') |
|||
local icons = require('Module:Icons')._main |
|||
local p = {} |
local p = {} |
||
Line 10: | Line 14: | ||
return string.format("[[File:%s|220px]]", image_name) |
return string.format("[[File:%s|220px]]", image_name) |
||
end |
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 |
|||
Line 25: | Line 52: | ||
{ name = 'chapters' }, |
{ name = 'chapters' }, |
||
{ name = 'translators' }, |
{ name = 'translators' }, |
||
{ name = ' |
{ name = 'units', func = formatUnits }, |
||
{ name = 'characters' }, |
{ name = 'characters', func = formatCharacters }, |
||
} |
} |
||
:setArgs(args) |
:setArgs(args) |
||
Line 57: | Line 84: | ||
}) |
}) |
||
:addRow({ |
:addRow({ |
||
{ tag = 'th', content = ' |
{ tag = 'th', content = 'Units', colspan = 12 }, |
||
{ tag = 'argtd', content = ' |
{ tag = 'argtd', content = 'units', colspan = 18 } |
||
}) |
}) |
||
:addRow({ |
:addRow({ |
Revision as of 21:11, 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 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 = 'translators' },
{ name = 'units', func = formatUnits },
{ name = 'characters', func = formatCharacters },
}
: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 = 'Translators', colspan = 12 },
{ tag = 'argtd', content = 'translators', 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 }
})
return infobox:tostring()
end
return p