Module:T-Person: Difference between revisions
// via Wikitext Extension for VSCode |
// via Wikitext Extension for VSCode |
||
| 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 TemplateHelpers | local TemplateHelpers = require('Module:TemplateHelpers') | ||
local ErrorHandling | local ErrorHandling = require('Module:ErrorHandling') | ||
local ConfigRepository = require('Module:ConfigRepository') | local ConfigRepository = require('Module:ConfigRepository') | ||
local LinkParser | local LinkParser = require('Module:LinkParser') | ||
local Achievements = require('Module:AchievementSystem') | |||
-- Blueprint default: Module-level cache for lazy-loaded modules | -- Blueprint default: Module-level cache for lazy-loaded modules | ||
| Line 25: | Line 26: | ||
-- Blueprint default: Modules to lazy load | -- Blueprint default: Modules to lazy load | ||
-- local getTemplateHelpers = lazyRequire('') | |||
local | |||
-- ==================== Helper Functions ==================== | -- ==================== Helper Functions ==================== | ||
local errorContext = ErrorHandling.createContext( | -- 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) | local function extractSemanticValue(fieldValue, fieldName) | ||
return TemplateHelpers.extractSemanticValue(fieldValue, fieldName, errorContext) | return TemplateHelpers.extractSemanticValue(fieldValue, fieldName, errorContext) | ||
| Line 42: | Line 40: | ||
-- IMPORTANT! TEMPLATE BLUEPRINT FRAMEWORK INSTRUCTIONS | -- IMPORTANT! TEMPLATE BLUEPRINT FRAMEWORK INSTRUCTIONS | ||
local template = Blueprint.registerTemplate(' | -- 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 = { | features = { | ||
title | title = true, | ||
logo | logo = true, | ||
fields | fields = true, | ||
socialMedia | socialMedia = true, | ||
semanticProperties = true, | semanticProperties = true, | ||
categories | categories = true, | ||
errorReporting | errorReporting = true, | ||
} | } | ||
}) | }) | ||
| Line 57: | Line 56: | ||
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', | ||
' | 'logo', | ||
'fields', | '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') | |||
-- | -- if template.features.navigation then | ||
-- local ElementExample = ErrorHandling.safeRequire(errorContext, 'Module:ElementNavigation', false) | |||
-- if ElementExample and ElementExample.elementName then | |||
-- Blueprint.registerElement(ElementExample.elementName, ElementExample) | |||
-- Blueprint.addElementToTemplate(template, 'example') | |||
local | -- end | ||
-- end | |||
end | |||
end | |||
-- | -- SPECIAL SEMANTIC MAPPINGS GO HERE | ||
-- | -- ================================================================================ | ||
-- ==================== 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 | ||
) | ) | ||