Module:Crime infobox
Jump to navigation
Jump to search
Documentation for this module may be created at Module:Crime infobox/doc
require('Module:No globals')
local infoboxStyle = mw.loadData('Module:WPMILHIST Infobox style')
local templatestyles = 'Module:Infobox military conflict/styles.css' -- reuse styles for now
local CrimeInfobox = {}
CrimeInfobox.__index = CrimeInfobox
function CrimeInfobox:render()
local args = self.args
local builder = mw.html.create()
builder = builder:tag('table')
:addClass('infobox vevent')
:cssText(infoboxStyle.main_box_raw)
-- Title
builder:tag('tr')
:tag('th')
:attr('colspan', 2)
:cssText(infoboxStyle.header_raw)
:wikitext(args.crime or mw.title.getCurrentTitle().text)
-- Subtitle (Part of ...)
if args.partof then
builder:tag('tr')
:tag('td')
:attr('colspan', 2)
:cssText(infoboxStyle.sub_header_raw)
:wikitext('Part of ' .. args.partof)
end
-- Image
if args.image then
builder:tag('tr')
:tag('td')
:attr('colspan', 2)
:cssText(infoboxStyle.image_box_raw)
:wikitext(require('Module:InfoboxImage').InfoboxImage{
args = {
image = args.image,
size = args.image_size,
sizedefault = 'frameless',
upright = 1,
alt = args.alt
}
} .. (args.caption and ('<br/>' .. args.caption) or ''))
end
-- Fields
local fields = {
{ label = 'Perpetrators', key = 'perpetrators' },
{ label = 'Date', key = 'date' },
{ label = 'Location', key = 'location' },
{ label = 'Victims', key = 'victims' },
{ label = 'Crime type', key = 'crime_type' },
{ label = 'Deaths', key = 'deaths' }
}
for _, field in ipairs(fields) do
if args[field.key] then
builder:tag('tr')
:tag('th')
:css('padding-right', '1em')
:wikitext(field.label)
:done()
:tag('td')
:wikitext(args[field.key])
end
end
return tostring(builder)
end
function CrimeInfobox.new(frame, args)
if not args then
args = require('Module:Arguments').getArgs(frame, {wrappers = 'Template:Crime infobox'})
end
return setmetatable({ args = args }, CrimeInfobox)
end
local p = {}
function p.main(frame)
return frame:extensionTag{ name = 'templatestyles', args = { src = templatestyles } } .. tostring(CrimeInfobox.new(frame):render())
end
return p