Module:T-Person: Difference between revisions
Appearance
// via Wikitext Extension for VSCode |
// via Wikitext Extension for VSCode |
||
| (42 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
-- Module:T-Person | -- Module:T-Person | ||
-- Blueprint | -- Makes use of ICANNWiki's "Template Blueprint Framework" to render the "Person" template | ||
local p = {} | local p = {} | ||
-- ==================== Required modules ==================== | -- ==================== Required modules ==================== | ||
local Blueprint | local Blueprint = require('Module:LuaTemplateBlueprint') | ||
local ErrorHandling = require('Module:ErrorHandling') | |||
local ErrorHandling | local LinkParser = require('Module:LinkParser') | ||
local Achievements = require('Module:AchievementSystem') | |||
local LinkParser | |||
local | |||
-- ==================== Helper Functions ==================== | -- ==================== Helper Functions ==================== | ||
local errorContext = ErrorHandling.createContext( | -- Blueprint default: Create error context for the module | ||
local errorContext = ErrorHandling.createContext("T-Person") | |||
-- ================================================================================ | -- ================================================================================ | ||
-- 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. | |||
local template = Blueprint.registerTemplate('Person', { | local template = Blueprint.registerTemplate('Person', { | ||
features = { | features = { | ||
title | title = true, | ||
logo | achievementHeader = true, | ||
fields | portraitCarousel = true, | ||
socialMedia | logo = true, | ||
fields = true, | |||
achievementBadges = true, | |||
socialMedia = true, | |||
semanticProperties = true, | semanticProperties = true, | ||
categories | categories = true, | ||
errorReporting | errorReporting = true, | ||
} | } | ||
}) | }) | ||
| Line 57: | Line 36: | ||
Blueprint.initializeConfig(template) | Blueprint.initializeConfig(template) | ||
-- CONTROL THE VISUAL ORDER | -- CONTROL THE VISUAL ORDER THAT EACH ASPECT IS RENDERED IN | ||
template.config.blockSequence = { | template.config.blockSequence = { | ||
'title', | 'title', | ||
'achievementHeader', | 'achievementHeader', | ||
'portraitCarousel', | 'portraitCarousel', | ||
'logo', | |||
'fields', | 'fields', | ||
'achievementsSectionHeader', | |||
'achievementBadges', | 'achievementBadges', | ||
'socialMedia' | 'socialMedia', | ||
'semanticProperties', | |||
'categories', | |||
'errors' | |||
} | } | ||
-- ================================================================================ | -- ================================================================================ | ||
-- | -- TEMPLATE-SPECIFIC CALLS AND CODE | ||
local function | |||
local pageId = | -- 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 | end | ||
-- | -- Get badge achievements using the centralized function | ||
local badgeAchievements = Achievements.getBadgeAchievements(pageId, template.current_frame) | |||
local | |||
-- Only render the header if there are badges to display | |||
if | if #badgeAchievements > 0 then | ||
return | local TemplateStructure = require('Module:TemplateStructure') | ||
return TemplateStructure.renderDividerBlock("Achievements") | |||
end | end | ||
return '' | return '' | ||
end | end | ||
template.config.blocks = template.config.blocks or {} | |||
template.config.blocks.achievementsSectionHeader = { | |||
render = function(template, args) | |||
return renderAchievementsHeader(template, args) | |||
end | |||
} | |||
-- | -- ELEMENT: ACHIEVEMENT HEADER | ||
local | if template.features.achievementHeader then | ||
if | local ElementAchievementHeader = ErrorHandling.safeRequire(errorContext, | ||
'Module:ElementAchievementHeader', false) | |||
if ElementAchievementHeader then | |||
Blueprint.registerElement(ElementAchievementHeader.elementName, ElementAchievementHeader) | |||
Blueprint.addElementToTemplate(template, 'achievementHeader') | |||
end | end | ||
local | end | ||
-- ELEMENT: ACHIEVEMENT BADGES | |||
if template.features.achievementBadges then | |||
if | local ElementAchievementBadges = ErrorHandling.safeRequire(errorContext, | ||
'Module:ElementAchievementBadges', false) | |||
if ElementAchievementBadges then | |||
Blueprint.registerElement(ElementAchievementBadges.elementName, ElementAchievementBadges) | |||
Blueprint.addElementToTemplate(template, 'achievementBadges') | |||
end | end | ||
end | end | ||
-- | -- ELEMENT: PORTRAIT CAROUSEL | ||
if template.features.portraitCarousel then | |||
local ElementPortraitCarousel = ErrorHandling.safeRequire(errorContext, | |||
'Module:ElementPortraitCarousel', false) | |||
if ElementPortraitCarousel then | |||
Blueprint.registerElement(ElementPortraitCarousel.elementName, ElementPortraitCarousel) | |||
-- 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 | ||
-- | -- PROCESSORS | ||
template.config.processors = { | |||
-- SOI field processor | |||
soi = function(value) | |||
if value and value ~= "" then | |||
return string.format("[%s Here]", value) | |||
if | |||
end | end | ||
return value | |||
end, | |||
} | |||
-- | -- ================================================================================ | ||
-- ==================== Preprocessors ==================== | -- ==================== Preprocessors ==================== | ||
Blueprint.addPreprocessor(template, 'setPageIdField') | -- Basic preprocessors | ||
Blueprint.addPreprocessor(template, 'setPageIdField') -- Blueprint default | |||
Blueprint.addPreprocessor(template, 'deriveRegionFromCountry') | |||
-- ==================== Main Render Function ==================== | -- ==================== Main Render Function ==================== | ||
-- Blueprint default: Render | |||
function p.render(frame) | function p.render(frame) | ||
return ErrorHandling.protect( | return ErrorHandling.protect( | ||
errorContext, | errorContext, | ||
"render", | |||
function() | function() | ||
return template.render(frame) | return template.render(frame) | ||
end, | end, | ||
ErrorHandling.getMessage( | ErrorHandling.getMessage("TEMPLATE_RENDER_ERROR"), | ||
frame | frame | ||
) | ) | ||
Latest revision as of 18:56, 8 July 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 ErrorHandling = require('Module:ErrorHandling')
local LinkParser = require('Module:LinkParser')
local Achievements = require('Module:AchievementSystem')
-- ==================== Helper Functions ====================
-- Blueprint default: Create error context for the module
local errorContext = ErrorHandling.createContext("T-Person")
-- ================================================================================
-- 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('Person', {
features = {
title = true,
achievementHeader = true,
portraitCarousel = true,
logo = true,
fields = true,
achievementBadges = 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',
'achievementHeader',
'portraitCarousel',
'logo',
'fields',
'achievementsSectionHeader',
'achievementBadges',
'socialMedia',
'semanticProperties',
'categories',
'errors'
}
-- ================================================================================
-- 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
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
local ElementPortraitCarousel = ErrorHandling.safeRequire(errorContext,
'Module:ElementPortraitCarousel', false)
if ElementPortraitCarousel then
Blueprint.registerElement(ElementPortraitCarousel.elementName, ElementPortraitCarousel)
-- 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
-- PROCESSORS
template.config.processors = {
-- SOI field processor
soi = function(value)
if value and value ~= "" then
return string.format("[%s Here]", value)
end
return value
end,
}
-- ================================================================================
-- ==================== Preprocessors ====================
-- Basic preprocessors
Blueprint.addPreprocessor(template, 'setPageIdField') -- Blueprint default
Blueprint.addPreprocessor(template, 'deriveRegionFromCountry')
-- ==================== 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