Module:Tribe Banner

local p = {} local h = {}

-- Helper functions

-- Check if a string is empty function h.isEmpty(str) return str == nil or str == '' end

-- Builds  and  tags function h.descriptionItem(reference, title, content) local dt = reference:tag('dt') dt :css('font-size', '1.15em') :css('font-variant', 'small-caps') :wikitext(title) local dd = reference:tag('dd') dd :css('font-style', 'italic') :wikitext(content)

return dt and dd end

-- Argument processing

function p.getArgs(args) local data = {}

-- Tribe name and status -- Ensure data.tribe doesn't get set as an empty string when this module is -- used in templates. if args['tribe'] and not h.isEmpty(args['tribe'] ) then data.tribe = args['tribe'] else data.tribe = 'noTribe' end -- Ensure data.canon doesn't get set as an empty string when this module is -- used in templates. if args['canon'] and not h.isEmpty(args['canon'] ) then data.canon = args['canon'] else data.canon = false end

-- Header fields -- Ensure the default sigil will always show up when this module is used in -- templates unless a custom sigil is actually set. if args['sigil'] and not h.isEmpty(args['sigil'] ) then data.sigil = args['sigil'] else data.sigil = 'SigilSolidBlank.svg' end

data.title = args['title'] or ''

-- Main fields data.description = args['description'] or false data.abilities  = args['abilities'] or false data.location   = args['location'] or false data.leader     = args['leader'] or false -- Ensure the default sigil will always show up when this module is used in -- templates unless a custom sigil is actually set. if args['leader-type'] and not h.isEmpty(args['leader-type'] ) then data.leaderType = args['leader-type'] else data.leaderType = 'Queen' end data.diet       = args['diet'] or false data.alliances  = args['alliances'] or false return data end

-- Main functions

function p.render(data) local container = mw.html.create('div') container :addClass('tribeBanner') :addClass('tribeBanner--' .. data.tribe) :css('margin', '5px auto 40px') :css('padding-top', '32px') :css('width', '96%') :css('font-family', '"Adelon Book", sans-serif')

-- Header wrapper local headerWrapper = container:tag('div') headerWrapper :addClass('tribeBanner__header') :css('position', 'relative') :css('box-sizing', 'border-box') :css('display', 'flex') :css('align-items', 'center') :css('margin', '0 0 10px') :css('padding-left', '134px') :css('min-height', '50px') :css('background-color', '#fff') :css('box-shadow', '1px 1px 4px 1px rgba(0,0,0,0.5)') :css('font-size', '1.3em') :css('font-variant', 'small-caps')

-- Header image local headerImage = headerWrapper:tag('div') headerImage :css('position', 'absolute') :css('left', '10px') :css('margin-right', '15px') :css('border', '7px solid #fff') :css('border-radius', '50%') :css('background-color', '#fff') :css('box-shadow', '0 0 3px 0 rgba(0,0,0,0.5)') :wikitext('')

-- Header title local headerTitle = headerWrapper:tag('p') headerTitle :wikitext(data.title)

-- Content wrapper local contentWrapper = container:tag('div') contentWrapper :addClass('tribeBanner__content') :css('box-sizing', 'border-box') :css('margin', '10px 0 0') :css('padding', '20px 20px 5px') :css('background-color', '#fff') :css('box-shadow', '1px 1px 4px 1px rgba(0,0,0,0.5)') :css('font-size', '1em') :css('line-height', '1.3')

-- Content definiton list wrapper local contentList = contentWrapper:tag('dl')

-- If data.description is set add description fields if data.description and not h.isEmpty(data.description) then h.descriptionItem(contentList, 'Description', data.description) end

-- If data.abilities is set add ability fields if data.abilities and not h.isEmpty(data.abilities) then h.descriptionItem(contentList, 'Abilities', data.abilities) end -- If data.location is set add location fields if data.location and not h.isEmpty(data.location) then h.descriptionItem(contentList, 'Location', data.location) end

-- If data.leader is set and the tribe is a _canon_ tribe add " (Canon)" -- onto the end of the leader type if data.leader and not h.isEmpty(data.leader) and data.canon then h.descriptionItem(contentList, data.leaderType .. ' (Canon)', data.leader) -- Else if data.leader add leader title field elseif data.leader and not h.isEmpty(data.leader) then h.descriptionItem(contentList, data.leaderType, data.leader) end

-- If data.diet is set add diet fields if data.diet and not h.isEmpty(data.diet) then h.descriptionItem(contentList, 'Diet', data.diet) end -- If data.alliances is set add allience fields if data.alliances and not h.isEmpty(data.alliances) then h.descriptionItem(contentList, 'Alliances', data.alliances) end

return tostring(container) end

-- Exports

function p.main(frame) local args = frame.args

local bannerData = p.getArgs(args) local banner = p.render(bannerData)

return banner end

return p