Module:ElementAchievementHeader: Difference between revisions
Appearance
// via Wikitext Extension for VSCode |
// via Wikitext Extension for VSCode |
||
| Line 47: | Line 47: | ||
-- Important: The CSS classes must be directly on the table cell element | -- Important: The CSS classes must be directly on the table cell element | ||
-- The CSS animations are attached to these elements via pseudo-elements | -- The CSS animations are attached to these elements via pseudo-elements | ||
-- Debug information to help diagnose the issue | |||
local debugInfo = string.format("<!-- Achievement Debug: ID=%s, Name=%s, Type=%s, PageID=%s -->", | |||
achievementId or "nil", | |||
displayName or "nil", | |||
achievementType or "nil", | |||
pageId or "nil") | |||
return string.format( | return string.format( | ||
'|-\n! colspan="2" class="%s %s" data-achievement-id="%s" data-achievement-name="%s" | %s', | '|-\n! colspan="2" class="%s %s" data-achievement-id="%s" data-achievement-name="%s" | %s%s', | ||
headerClass, achievementId, achievementId, displayName, displayName | headerClass, achievementId, achievementId, displayName, displayName, debugInfo | ||
) | ) | ||
end | end | ||
Revision as of 00:33, 7 May 2025
Documentation for this module may be created at Module:ElementAchievementHeader/doc
--[[
* Module:ElementAchievementHeader
* Renders the achievement header for person templates
* Displays title achievements with special styling
*
* Integrates with Blueprint template system.
]]
local p = {}
p.elementName = "achievementHeader"
-- Load required modules
local ErrorHandling = require('Module:ErrorHandling')
local Achievements = require('Module:AchievementSystem')
-- Default configuration
p.defaultConfig = {
headerClass = "achievement-header"
}
-- Create block function
function p.createBlock()
return function(template, args)
-- Protected execution wrapper
local function execute()
-- Get the current page ID
local pageId = mw.title.getCurrentTitle().id
if not pageId then
return "" -- No page ID, can't get achievements
end
-- Get title achievement data with frame for JSON loading
local achievementId, displayName, achievementType = Achievements.getTitleAchievement(pageId, mw.getCurrentFrame())
-- If no title achievement found, return empty string
if not achievementId or achievementId == "" then
return ""
end
-- Create the achievement header HTML
local headerClass = template.config.achievementHeader
and template.config.achievementHeader.headerClass
or p.defaultConfig.headerClass
-- Build header HTML properly aligned with CSS expectations in Achievements.css
-- Important: The CSS classes must be directly on the table cell element
-- The CSS animations are attached to these elements via pseudo-elements
-- Debug information to help diagnose the issue
local debugInfo = string.format("<!-- Achievement Debug: ID=%s, Name=%s, Type=%s, PageID=%s -->",
achievementId or "nil",
displayName or "nil",
achievementType or "nil",
pageId or "nil")
return string.format(
'|-\n! colspan="2" class="%s %s" data-achievement-id="%s" data-achievement-name="%s" | %s%s',
headerClass, achievementId, achievementId, displayName, displayName, debugInfo
)
end
-- Wrap with error handling
if template._errorContext then
return ErrorHandling.protect(
template._errorContext,
"ElementBlock_achievementHeader",
execute,
""
)
else
local ok, result = pcall(execute)
return ok and result or ""
end
end
end
return p