Module:InfoboxRole
Jump to navigation
Jump to search
Documentation for this module may be created at Module:InfoboxRole/doc
local p = {}
-- Define the CSS variables/hex codes as Lua constants for use in inline styles
local STYLE_FLOATING = 'float: right !important; clear: right !important; max-width: 300px !important; margin: 0 0 16px 16px !important; border: 1px solid #1a6a7a !important; border-radius: 10px !important; background-color: #FFFFFF !important; font-size: .9em !important;'
local STYLE_HEADER = 'background: #1a6a7a !important; color: white !important; padding: 8px 10px !important; text-align: center !important; font-weight: bold !important; font-size: 1.5em !important; border-top-left-radius: 10px !important; border-top-right-radius: 10px !important;'
local STYLE_DATAROW = 'display: flex !important; justify-content: space-between !important; padding: 5px 10px !important; border-bottom: 1px dotted #A2A9B1 !important;'
local STYLE_DATALABEL = 'font-weight: 500 !important; color: #4A5568 !important; width: 40% !important; text-align: left !important;'
local STYLE_DATAVALUE = 'color: #4A5568 !important; text-align: right !important; width: 60% !important;'
-- Function to generate a single data row
local function make_data_row(label, value)
if value and value ~= '' then
return string.format(
'<div style="%s"><span style="%s">%s:</span> <span style="%s">%s</span></div>',
STYLE_DATAROW,
STYLE_DATALABEL,
label,
STYLE_DATAVALUE,
value
)
end
return ''
end
-- Function to create a section header
local function make_section_header(title)
if title and title ~= '' then
return string.format(
'<div class="section-title" style="padding: 5px 10px; color: #4A5568 !important; font-weight: bold; border-bottom: 1px solid #A2A9B1;">%s</div>',
title
)
end
return ''
end
-- Main function to create the role infobox HTML
function p.infobox(frame)
local args = frame:getParent().args
local name = args.name or 'Unknown Role'
local image = args.image
local html = {}
-- Start the main infobox container
table.insert(html, string.format('<div class="role-infobox" style="%s">', STYLE_FLOATING))
-- Header/Title
table.insert(html, string.format('<div class="role-header" style="%s">%s</div>', STYLE_HEADER, name))
-- Image Section
if image and image ~= '' then
local image_link = string.format('[[File:%s|250px|alt=%s]]', image, name)
table.insert(html, string.format('<div class="role-image" style="padding: 10px !important; text-align: center !important;">%s</div>', image_link))
end
-- Start Role Information Section
table.insert(html, '<div class="role-section">')
table.insert(html, make_section_header('Role Information'))
-- Data Rows (Using make_data_row function)
table.insert(html, make_data_row('Role Type', args.role_type))
table.insert(html, make_data_row('Rank', args.rank))
table.insert(html, make_data_row('Located In', args.located_in))
table.insert(html, make_data_row('Category', args.category))
table.insert(html, make_data_row('Reports To', args.reports_to))
table.insert(html, make_data_row('Supervises', args.supervises))
-- End role section
table.insert(html, '</div>')
-- Start Additional Details Section (if any additional fields)
local hasAdditional = args.responsibilities or args.prerequisites or args.equipment or args.notes
if hasAdditional then
table.insert(html, '<div class="role-section">')
table.insert(html, make_section_header('Additional Details'))
table.insert(html, make_data_row('Prerequisites', args.prerequisites))
table.insert(html, make_data_row('Equipment', args.equipment))
-- End additional section
table.insert(html, '</div>')
end
-- End container
table.insert(html, '</div>') -- End role-infobox
return table.concat(html, '\n')
end
-- Function for creating simplified infobox for template usage
function p.create(frame)
return p.infobox(frame)
end
return p