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

-- Ensure the variable doesn't get set as an empty string when this -- module is used inside templates. function h.complexVar(templateArg, default) if templateArg and not h.isEmpty(templateArg) then var = templateArg else var = default end

return var end

-- Build a  tag function h.descriptionTitle(reference, data) local dt = reference:tag('dt') dt :css('font-size', '1.15em') :css('font-variant', 'small-caps') :wikitext(data)

return dt end

-- Build a  tag function h.descriptionData(reference, data) local dd = reference:tag('dd') dd :css('font-style', 'italic') :wikitext(data)

return dt end

-- Builds  and  group function h.descriptionGroup(reference, title, content) -- If `content` is set add the appropriate field to the banner. if content and not h.isEmpty(content) then local dt = h.descriptionTitle(reference, title) local dd = h.descriptionData(reference, content) end

return dt and dd end

-- Builds  and  group with extra options function h.complexDescriptionGroup(reference, title, titleExtra, isCanon, content) -- If `content` and `titleExtra` are both set if content and not h.isEmpty(content) and isCanon then local dt = h.descriptionTitle(reference, title .. titleExtra) local dd = h.descriptionData(reference, content) -- Else if only `content` is set elseif content and not h.isEmpty(content) then local dt = h.descriptionTitle(reference, title) local dd = h.descriptionData(reference, content) end

return dt and dd end

-- Argument processing

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

-	-- Tribe name and canonicity -	data.tribe = h.complexVar(args['tribe'], 'noTribe') data.canon = h.complexVar(args['canon'], false)

-	-- Header fields -	data.sigil = h.complexVar(args['sigil'], 'SigilSolidBlank.svg') 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 data.leaderType = h.complexVar(args['leader-type'], 'Queen') data.leader2    = args['leader-2'] or false data.leaderType2 = h.complexVar(args['leader-type-2'], 'Queen') 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('border-box') :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') :css('color', '#222')

-- Header wrapper local headerWrapper = container:tag('div') headerWrapper :addClass('tribeBanner__header') :css('position', 'relative') :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('border', '5px 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('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')

-- Tribe appearance h.descriptionGroup(contentList, 'Description', data.description) -- Tribe abilities h.descriptionGroup(contentList, 'Abilities', data.abilities) -- Tribe residence h.descriptionGroup(contentList, 'Location', data.location) -- Tribe leader h.complexDescriptionGroup(		contentList,		data.leaderType,		' (Canon)',		data.canon,		data.leader	) -- Tribe alternate leader h.complexDescriptionGroup(		contentList,		data.leaderType2,		' (Canon)',		data.canon,		data.leader2	) -- Tribe diet h.descriptionGroup(contentList, 'Diet', data.diet) -- Tribe alliances h.descriptionGroup(contentList, 'Alliances', data.alliances)

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