Module:T-Process: Difference between revisions
Appearance
// via Wikitext Extension for VSCode |
// via Wikitext Extension for VSCode |
||
| Line 72: | Line 72: | ||
-- Add a preprocessor to handle process connections directly | -- Add a preprocessor to handle process connections directly | ||
Blueprint.addPreprocessor(template, function(template, args) | Blueprint.addPreprocessor(template, function(template, args) | ||
-- Create a table to store the connections | -- Create a table to store the connections | ||
local connections = {} | local connections = {} | ||
| Line 93: | Line 90: | ||
addConnection(args.has_next, "Succeeded By") | addConnection(args.has_next, "Succeeded By") | ||
-- Store | -- Store each connection as a separate property with a special key | ||
-- This approach is similar to how T-LibraryInterview.lua handles properties | |||
for i, connection in ipairs(connections) do | |||
args["_processConnection" .. i] = connection | |||
end | |||
return args | return args | ||
end) | end) | ||
-- | -- Configure semantic properties to use the special keys | ||
-- This replaces the custom property provider with standard property mappings | |||
template.config.semantics = template.config.semantics or {} | |||
template.config.semantics.properties = template.config.semantics.properties or {} | |||
-- Add property mappings for each potential connection (up to 5 connections) | |||
local processConnectionProperty = require('Module:ConfigRepository').semanticProperties.process_connection | |||
for i = 1, 5 do | |||
template.config.semantics.additionalProperties = template.config.semantics.additionalProperties or {} | |||
template.config.semantics.additionalProperties[processConnectionProperty] = template.config.semantics.additionalProperties[processConnectionProperty] or {} | |||
table.insert(template.config.semantics.additionalProperties[processConnectionProperty], "_processConnection" .. i) | |||
end | |||
end | |||
-- ========== Main Render Function ========== | -- ========== Main Render Function ========== | ||
Revision as of 17:42, 26 April 2025
Documentation for this module may be created at Module:T-Process/doc
--Module:T-Process
-- Renders the "Process" template for governance processes and initiatives, making use of ICANNWiki's "Template Blueprint Framework"
local p = {}
-- ========== Required modules ==========
local Blueprint = require('Module:LuaTemplateBlueprint')
local ConfigRepository = require('Module:ConfigRepository')
local ErrorHandling = require('Module:ErrorHandling')
local LinkParser = require('Module:LinkParser')
-- 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-Process")
-- ================================================================================
-- 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('Process', {
features = {
title = true,
logo = true,
fields = true,
socialMedia = true,
semanticProperties = true,
categories = true,
errorReporting = true
}
})
-- Initialize the standard configuration
Blueprint.initializeConfig(template)
-- ================================================================================
-- ========== Preprocessors ==========
-- Basic preprocessors
Blueprint.addPreprocessor(template, 'setPageIdField')
Blueprint.addPreprocessor(template, 'deriveRegionFromCountry')
-- Helper function to extract plain text from wiki links for semantic properties
local TemplateHelpers = require('Module:TemplateHelpers')
local function extractSemanticValue(fieldValue, fieldName)
return TemplateHelpers.extractSemanticValue(fieldValue, fieldName, errorContext)
end
-- Get the SemanticCategoryHelpers module
local SemanticCategoryHelpers = require('Module:SemanticCategoryHelpers')
-- Override the skipProperties to ensure we handle the process_connection property
template.config.semantics = template.config.semantics or {}
template.config.semantics.skipProperties = template.config.semantics.skipProperties or {}
template.config.semantics.skipProperties[require('Module:ConfigRepository').semanticProperties.process_connection] = true
-- Add a preprocessor to handle process connections directly
Blueprint.addPreprocessor(template, function(template, args)
-- Create a table to store the connections
local connections = {}
-- Helper function to add a connection if valid
local function addConnection(value, fieldName)
if value and value ~= "" then
local extractedValue = extractSemanticValue(value, fieldName)
if extractedValue and extractedValue ~= "" then
table.insert(connections, extractedValue)
end
end
end
-- Add connections from all relevant fields
addConnection(args.process, "Process")
addConnection(args.has_previous, "Preceded By")
addConnection(args.has_next, "Succeeded By")
-- Store each connection as a separate property with a special key
-- This approach is similar to how T-LibraryInterview.lua handles properties
for i, connection in ipairs(connections) do
args["_processConnection" .. i] = connection
end
return args
end)
-- Configure semantic properties to use the special keys
-- This replaces the custom property provider with standard property mappings
template.config.semantics = template.config.semantics or {}
template.config.semantics.properties = template.config.semantics.properties or {}
-- Add property mappings for each potential connection (up to 5 connections)
local processConnectionProperty = require('Module:ConfigRepository').semanticProperties.process_connection
for i = 1, 5 do
template.config.semantics.additionalProperties = template.config.semantics.additionalProperties or {}
template.config.semantics.additionalProperties[processConnectionProperty] = template.config.semantics.additionalProperties[processConnectionProperty] or {}
table.insert(template.config.semantics.additionalProperties[processConnectionProperty], "_processConnection" .. i)
end
-- ========== Main Render Function ==========
-- Blueprint default: Main render function
function p.render(frame)
return ErrorHandling.protect(
errorContext,
"render",
function()
return template.render(frame)
end,
ErrorHandling.getMessage("TEMPLATE_RENDER_ERROR"),
frame
)
end
return p