Module:InfoboxTitle/hex

From Inkipedia, the Splatoon wiki

Documentation for this module may be created at Module:InfoboxTitle/hex/doc

local p = {}
local siteColor = require('Module:SiteColor/hex')  -- Import the SiteColor module

function p.requireFromModule(frame)
	return p.getTitle(frame)
end

function p.invokeFromTemplate(frame)
	return p.getTitle(frame:getParent().args)
end

-- Function to render the div with styles
function p.getTitle(args)
	-- content is first unnamed argument. Made bold by default.
	local content = string.format("\'\'\'%s\'\'\'", args[1]) or ''
	-- color argument or default to Generic. Expected to be hex (e.g., #FFFFFF)
	local color = args['color'] or siteColor.getSiteColor("Generic")
	-- Get any additional styles
	local style = args['style'] or ''

	-- Start the HTML div string
	local styleTable = {}

	-- Add the styles
	table.insert(styleTable, 'padding: 10px;')
	table.insert(styleTable, string.format('background: %s4D;', color))
	table.insert(styleTable, 'border-width: 1px 5px 1px 5px;')
	table.insert(styleTable, 'border-style: solid;')
	table.insert(styleTable, string.format('border-color: %s80;', color))
	table.insert(styleTable, 'border-radius: 5px 5px 5px 5px;')
	table.insert(styleTable, 'text-align: center;')
	table.insert(styleTable, 'font-size: 20px;')

	-- Add any additional styles
	if style and style ~= '' then
		table.insert(styleTable, style)
	end

	-- Close the style attribute and add the content
	return string.format("<div style=\"%s\">%s</div>", table.concat(styleTable, " "), content)
end

return p