Module: Infobox house
From A Wiki of Ice and Fire
This module implements {{Infobox house}}
.
local getArgs = require('Module:Arguments').getArgs
local tt = require('Module:TableTools')
local ib = require('Module:Infobox maker')
local br = require('Module:Separated entries').br
local date = require('Module:Date')._format
local function is_empty(s)
-- This function checks whether a string is empty
return s == nil or s == ''
end
local function get_region(region)
region = region or ""
regions = {
crownlands = "Crownlands",
dorne = "Dorne",
ironislands = "Iron Islands",
ironisland = "Iron Islands",
ironisles = "Iron Islands",
ironisle = "Iron Islands",
thenorth = "North",
north = "North",
reach = "Reach",
riverlands = "Riverlands",
stormlands = "Stormlands",
vale = "Vale of Arryn",
valeofarryn = "Vale of Arryn",
westerlands = "Westerlands",
}
local default = regions[mw.ustring.lower(region):gsub('%W','')]
return not is_empty(default) and ("[[" .. default .. "]]") or region
end
local p = {}
function p.main(frame)
local args = getArgs(frame)
ib.initialize(args)
--- General styling
ib.add_classes{
bodyclass = "plainlist",
titleclass = "",
aboveclass = "",
imageclass = "",
belowclass = "",
}
ib.add_styles{
bodystyle = "",
titlestyle = "",
abovestyle = "",
imagestyle = "",
captionstyle = "font-size:120%;",
headerstyle = "background-color:#f8e9d0;border:none;",
labelstyle = "white-space:nowrap;",
datastyle = "",
belowstyle = "",
}
local house = args.house or ""
local of = args.of or ""
local region = get_region(args.region)
local title = not is_empty(house) and ("House " .. house) or "House ???"
local subtitle = ""
if not is_empty(of) then
subtitle = mw.html.create('span')
subtitle:css('font-size', '80%')
:css('font-weight', 'normal')
:wikitext("of " .. of)
end
ib.add_above{
above = br({
title,
tostring(subtitle),
}),
}
local image_auto1 = "House " .. house .. " (" .. of .. ").svg"
local image_auto2 = "House " .. house .. ".svg"
local image_default = (region == '[[Dorne]]') and 'None (Dorne).svg' or 'None.svg'
local image = args.image or
(mw.title.new(image_auto1, 'File').exists and image_auto1) or
(mw.title.new(image_auto2, 'File').exists and image_auto2) or
image_default
ib.add_image{
image = image,
size = '250px',
alt = args.alt or args.arms,
border = 'no',
suppressplaceholder = 'no',
caption = not is_empty(args.words) and ("“" .. args.words .. "”")
}
if image == 'None.svg' or image == 'None (Dorne).svg' then
ib.add_category{name="Houses without COA", key=house}
else
ib.add_category{name="Houses with COA", key=house}
end
ib.add_row{
label = "Arms",
data = args.arms,
}
ib.add_row{
label = "Blazon",
data = args.blazon,
rowstyle = "font-style:italic;",
}
ib.add_row{
label = "Seat",
data = args.seat or (not is_empty(of) and "[[" .. of .. "]]"),
}
ib.add_row{
label = "Region",
data = region,
}
ib.add_row_list{
singular = "Title",
plural = "Titles",
prefix = 'title',
}
local founded = date(args.founded)
local extinct = date(args.extinct)
local lord = args.lord
local lady = args.lady
ib.add_row{
label = (is_empty(extinct) and "Current " or "Last ") .. (is_empty(lady) and "lord" or "lady"),
data = is_empty(lady) and lord or lady,
}
if is_empty(extinct) then
ib.add_row{
label = "Heir",
data = args.heir,
}
end
ib.add_row{
label = "Vassal of",
data = args.overlord,
}
ib.add_row_list{
singular = "Cadet branch",
plural = "Cadet branches",
prefix = 'cadet',
}
ib.add_row_list{
singular = "Ancestral weapon",
plural = "Ancestral weapons",
prefix = 'weapon',
}
ib.add_row{
label = "Founded",
data = founded,
}
ib.add_row{
label = "Founder",
data = args.founder,
}
ib.add_row{
label = "Extinct",
data = extinct,
}
return ib.make_infobox()
end
return p