Module:T-Person: Difference between revisions
Appearance
// via Wikitext Extension for VSCode |
// via Wikitext Extension for VSCode |
||
| Line 114: | Line 114: | ||
local normalized = {} | local normalized = {} | ||
-- Normalize language names | |||
for i, language in ipairs(languages) do | for i, language in ipairs(languages) do | ||
normalized[i] = NormalizationLanguage.normalize(language) or language | normalized[i] = NormalizationLanguage.normalize(language) or language | ||
end | end | ||
return table.concat( | -- 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 | end | ||
} | } | ||
Revision as of 23:01, 6 May 2025
Documentation for this module may be created at Module:T-Person/doc
-- Module:T-Person
-- Makes use of ICANNWiki's "Template Blueprint Framework" to render the "Person" template
local p = {}
-- ==================== Required modules ====================
local Blueprint = require('Module:LuaTemplateBlueprint')
local TemplateHelpers = require('Module:TemplateHelpers')
local ErrorHandling = require('Module:ErrorHandling')
local ConfigRepository = require('Module:ConfigRepository')
local LinkParser = require('Module:LinkParser')
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 ====================
-- Blueprint default: Create error context for the module
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
-- ================================================================================
-- 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.
local template = Blueprint.registerTemplate('Person2', {
features = {
title = true,
logo = true,
portraitCarousel = true,
fields = true,
socialMedia = true,
semanticProperties = true,
categories = true,
errorReporting = true,
}
})
-- Blueprint default: Initialize standard configuration
Blueprint.initializeConfig(template)
-- CONTROL THE VISUAL ORDER THAT EACH ASPECT IS RENDERED IN
template.config.blockSequence = {
'title',
'portraitCarousel',
'logo',
'fields',
'socialMedia',
'semanticProperties',
'categories',
'errors'
}
-- ================================================================================
-- TEMPLATE-SPECIFIC CALLS AND CODE
-- ELEMENTS GO HERE
-- Safely load element modules with ErrorHandling.safeRequire, then register them via Blueprint.addElementToTemplate(template, 'example')
-- Register the portrait carousel element
if template.features.portraitCarousel then
local ElementPortraitCarousel = ErrorHandling.safeRequire(errorContext,
'Module:ElementPortraitCarousel', false)
if ElementPortraitCarousel then
Blueprint.registerElement(ElementPortraitCarousel.elementName, ElementPortraitCarousel)
Blueprint.addElementToTemplate(template, 'portraitCarousel')
end
end
-- SPECIAL SEMANTIC MAPPINGS GO HERE
-- ================================================================================
-- ==================== Preprocessors ====================
-- Basic preprocessors
Blueprint.addPreprocessor(template, 'setPageIdField') -- Blueprint default
Blueprint.addPreprocessor(template, 'deriveRegionFromCountry')
-- ==================== Custom Configuration ====================
-- Initialize processor functions for fields
template.config.processors = {
-- SOI field processor to format SOI as a link
soi = function(value)
if value and value ~= "" then
return string.format("[%s Here]", value)
end
return value
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
}
-- ==================== Main Render Function ====================
-- Blueprint default: Render
function p.render(frame)
return ErrorHandling.protect(
errorContext,
"render",
function()
return template.render(frame)
end,
ErrorHandling.getMessage("TEMPLATE_RENDER_ERROR"),
frame
)
end
return p