Module:T-Person: Difference between revisions

// via Wikitext Extension for VSCode
// via Wikitext Extension for VSCode
 
(32 intermediate revisions by the same user not shown)
Line 6: Line 6:
-- ==================== Required modules ====================
-- ==================== Required modules ====================
local Blueprint = require('Module:LuaTemplateBlueprint')
local Blueprint = require('Module:LuaTemplateBlueprint')
local TemplateHelpers = require('Module:TemplateHelpers')
local ErrorHandling = require('Module:ErrorHandling')
local ErrorHandling = require('Module:ErrorHandling')
local ConfigRepository = require('Module:ConfigRepository')
local LinkParser = require('Module:LinkParser')
local LinkParser = require('Module:LinkParser')
local Achievements = require('Module:AchievementSystem')
local Achievements = require('Module:AchievementSystem')
-- Blueprint default: Module-level cache for lazy-loaded modules
local moduleCache = {}
-- Blueprint default: Lazy module loader
local function lazyRequire(moduleName)
    return function()
        if not moduleCache[moduleName] then
            moduleCache[moduleName] = require(moduleName)
        end
        return moduleCache[moduleName]
    end
end
-- Blueprint default: Modules to lazy load
    -- local getTemplateHelpers = lazyRequire('')


-- ==================== Helper Functions ====================
-- ==================== Helper Functions ====================
-- Blueprint default: Create error context for the module
-- Blueprint default: Create error context for the module
local errorContext = ErrorHandling.createContext("T-Person")
local errorContext = ErrorHandling.createContext("T-Person")
-- Blueprint default: Helper for extracting semantic values from wiki links
local function extractSemanticValue(fieldValue, fieldName)
    return TemplateHelpers.extractSemanticValue(fieldValue, fieldName, errorContext)
end


-- ================================================================================
-- ================================================================================
Line 41: Line 18:
-- IMPORTANT! TEMPLATE BLUEPRINT FRAMEWORK INSTRUCTIONS
-- IMPORTANT! TEMPLATE BLUEPRINT FRAMEWORK INSTRUCTIONS
-- CONTROL OF TEMPLATE FEATURES: THIS LIST SPECIFIES IN AN EXPLICIT MANNER WHAT FEATURES ARE TO BE CALLED/RENDERED BY THE TEMPLATE.
-- CONTROL OF TEMPLATE FEATURES: THIS LIST SPECIFIES IN AN EXPLICIT MANNER WHAT FEATURES ARE TO BE CALLED/RENDERED BY THE TEMPLATE.
local template = Blueprint.registerTemplate('Person2', {
local template = Blueprint.registerTemplate('Person', {
     features = {
     features = {
         title = true,
         title = true,
        achievementHeader = true,
        portraitCarousel = true,
         logo = true,
         logo = true,
        portraitCarousel = true,
         fields = true,
         fields = true,
        achievementBadges = true,
         socialMedia = true,
         socialMedia = true,
         semanticProperties = true,
         semanticProperties = true,
Line 56: Line 35:
-- Blueprint default: Initialize standard configuration
-- Blueprint default: Initialize standard configuration
Blueprint.initializeConfig(template)
Blueprint.initializeConfig(template)
-- Set the template ID and title styling options
template.config.meta = template.config.meta or {}
template.config.meta.templateId = "person"
template.config.meta.titleOptions = {
    className = "template-title-person" -- Apply the CSS class for green background
}


-- CONTROL THE VISUAL ORDER THAT EACH ASPECT IS RENDERED IN
-- CONTROL THE VISUAL ORDER THAT EACH ASPECT IS RENDERED IN
template.config.blockSequence = {
template.config.blockSequence = {
     'title',
     'title',
    'achievementHeader',
     'portraitCarousel',
     'portraitCarousel',
     'logo',
     'logo',
     'fields',
     'fields',
    'achievementsSectionHeader',
    'achievementBadges',
     'socialMedia',
     'socialMedia',
     'semanticProperties',
     'semanticProperties',
Line 80: Line 55:
-- TEMPLATE-SPECIFIC CALLS AND CODE
-- TEMPLATE-SPECIFIC CALLS AND CODE


-- ELEMENTS GO HERE
-- BLOCK: ACHIEVEMENTS SECTION HEADER
-- Safely load element modules with ErrorHandling.safeRequire, then register them via Blueprint.addElementToTemplate(template, 'example')
local function renderAchievementsHeader(template, args)
    -- Get the current page ID from the arguments pre-filled by the 'setPageIdField' preprocessor
    local pageId = args.ID
    if not pageId or pageId == '' then
        return ''
    end


-- Register the portrait carousel element
    -- Get badge achievements using the centralized function
    local badgeAchievements = Achievements.getBadgeAchievements(pageId, template.current_frame)
 
    -- Only render the header if there are badges to display
    if #badgeAchievements > 0 then
        local TemplateStructure = require('Module:TemplateStructure')
        return TemplateStructure.renderDividerBlock("Achievements")
    end
 
    return ''
end
template.config.blocks = template.config.blocks or {}
template.config.blocks.achievementsSectionHeader = {
    render = function(template, args)
        return renderAchievementsHeader(template, args)
    end
}
 
-- ELEMENT: ACHIEVEMENT HEADER
if template.features.achievementHeader then
    local ElementAchievementHeader = ErrorHandling.safeRequire(errorContext,
        'Module:ElementAchievementHeader', false)
    if ElementAchievementHeader then
        Blueprint.registerElement(ElementAchievementHeader.elementName, ElementAchievementHeader)
        Blueprint.addElementToTemplate(template, 'achievementHeader')
    end
end
 
-- ELEMENT: ACHIEVEMENT BADGES
if template.features.achievementBadges then
    local ElementAchievementBadges = ErrorHandling.safeRequire(errorContext,
        'Module:ElementAchievementBadges', false)
    if ElementAchievementBadges then
        Blueprint.registerElement(ElementAchievementBadges.elementName, ElementAchievementBadges)
        Blueprint.addElementToTemplate(template, 'achievementBadges')
    end
end
 
-- ELEMENT: PORTRAIT CAROUSEL
if template.features.portraitCarousel then
if template.features.portraitCarousel then
     local ElementPortraitCarousel = ErrorHandling.safeRequire(errorContext,  
     local ElementPortraitCarousel = ErrorHandling.safeRequire(errorContext,  
Line 89: Line 107:
     if ElementPortraitCarousel then
     if ElementPortraitCarousel then
         Blueprint.registerElement(ElementPortraitCarousel.elementName, ElementPortraitCarousel)
         Blueprint.registerElement(ElementPortraitCarousel.elementName, ElementPortraitCarousel)
         Blueprint.addElementToTemplate(template, 'portraitCarousel')
       
        -- Add the element with a custom wrapper that creates a separate table row
         Blueprint.addElementToTemplate(template, 'portraitCarousel', {
            wrapperTemplate = '|-\n| colspan="2" class="person-portrait-row" |%s'
        })
     end
     end
end
end


-- SPECIAL SEMANTIC MAPPINGS GO HERE
-- PROCESSORS
 
-- ================================================================================
 
-- ==================== Preprocessors ====================
-- Basic preprocessors
Blueprint.addPreprocessor(template, 'setPageIdField')  -- Blueprint default
Blueprint.addPreprocessor(template, 'deriveRegionFromCountry')
 
-- ==================== Custom Configuration ====================
-- Initialize processor functions for fields
template.config.processors = {
template.config.processors = {
     -- SOI field processor to format SOI as a link
     -- SOI field processor
     soi = function(value)
     soi = function(value)
         if value and value ~= "" then
         if value and value ~= "" then
Line 113: Line 125:
     end,
     end,
      
      
    -- Languages field processor with normalization
    languages = function(value)
        if not value or value == "" then return value end
       
        local NormalizationLanguage = require('Module:NormalizationLanguage')
        local languages = TemplateHelpers.splitMultiValueString(value)
        local normalized = {}
       
        -- Normalize language names
        for i, language in ipairs(languages) do
            normalized[i] = NormalizationLanguage.normalize(language) or language
        end
       
        -- Format as HTML list
        local listItems = {}
        for i, language in ipairs(normalized) do
            listItems[i] = string.format("<li>%s</li>", language)
        end
       
        return string.format('<ul class="template-list template-list-language">%s</ul>',
            table.concat(listItems, ""))
    end
}
}
-- ================================================================================
-- ==================== Preprocessors ====================
-- Basic preprocessors
Blueprint.addPreprocessor(template, 'setPageIdField')  -- Blueprint default
Blueprint.addPreprocessor(template, 'deriveRegionFromCountry')


-- ==================== Main Render Function ====================
-- ==================== Main Render Function ====================