Module:T-Person: Difference between revisions

// via Wikitext Extension for VSCode
// via Wikitext Extension for VSCode
 
(15 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 45: Line 22:
         title = true,
         title = true,
         achievementHeader = true,
         achievementHeader = true,
         achievementBadges = true,
         portraitCarousel = true,
         logo = true,
         logo = true,
        portraitCarousel = true,
         fields = true,
         fields = true,
        achievementBadges = true,
         socialMedia = true,
         socialMedia = true,
         semanticProperties = true,
         semanticProperties = true,
Line 58: Line 35:
-- Blueprint default: Initialize standard configuration
-- Blueprint default: Initialize standard configuration
Blueprint.initializeConfig(template)
Blueprint.initializeConfig(template)
-- Set the template ID
template.config.meta = template.config.meta or {}
template.config.meta.templateId = "person"


-- CONTROL THE VISUAL ORDER THAT EACH ASPECT IS RENDERED IN
-- CONTROL THE VISUAL ORDER THAT EACH ASPECT IS RENDERED IN
Line 70: Line 43:
     'logo',
     'logo',
     'fields',
     'fields',
    'achievementsSectionHeader',
    'achievementBadges',
     'socialMedia',
     'socialMedia',
     'semanticProperties',
     'semanticProperties',
Line 79: Line 54:


-- TEMPLATE-SPECIFIC CALLS AND CODE
-- TEMPLATE-SPECIFIC CALLS AND CODE
-- BLOCK: ACHIEVEMENTS SECTION HEADER
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
    -- 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
-- ELEMENT: ACHIEVEMENT HEADER
Line 114: Line 115:
end
end


-- SPECIAL SEMANTIC MAPPINGS GO HERE
-- PROCESSORS
-- Languages are handled in the processors section below
 
-- ================================================================================
 
-- ==================== 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
     -- SOI field processor
Line 135: Line 125:
     end,
     end,
      
      
    -- Languages field processor with native name display and semantic properties
    languages = function(value)
        if not value or value == "" then return value end
       
        -- Use the NormalizationLanguage module for formatting display
        local NormalizationLanguage = require('Module:NormalizationLanguage')
        NormalizationLanguage.setShowNativeForms(true)
       
        -- Process semantic property for languages
        local SemanticCategoryHelpers = require('Module:SemanticCategoryHelpers')
        local semanticOutput = SemanticCategoryHelpers.addSemanticProperties("language", value, "")
       
        -- Return formatted display value with native names
        return NormalizationLanguage.formatLanguages(value)
    end
}
}
-- ================================================================================
-- ==================== Preprocessors ====================
-- Basic preprocessors
Blueprint.addPreprocessor(template, 'setPageIdField')  -- Blueprint default
Blueprint.addPreprocessor(template, 'deriveRegionFromCountry')


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