Jump to content

Module:T-Process: Difference between revisions

// via Wikitext Extension for VSCode
// via Wikitext Extension for VSCode
Line 65: Line 65:
local SemanticCategoryHelpers = require('Module:SemanticCategoryHelpers')
local SemanticCategoryHelpers = require('Module:SemanticCategoryHelpers')


-- Override the skipProperties to ensure we handle the process_connection property
-- TEMPORARILY DISABLE ALL PROCESS CONNECTION HANDLING
-- This is a minimal approach to isolate the issue
 
-- Ensure we skip the process_connection property completely
template.config.semantics = template.config.semantics or {}
template.config.semantics = template.config.semantics or {}
template.config.semantics.skipProperties = template.config.semantics.skipProperties or {}
template.config.semantics.skipProperties = template.config.semantics.skipProperties or {}
template.config.semantics.skipProperties[require('Module:ConfigRepository').semanticProperties.process_connection] = true
template.config.semantics.skipProperties[require('Module:ConfigRepository').semanticProperties.process_connection] = true


-- Add a preprocessor to handle process connections directly
-- Remove all process connection fields from the template
Blueprint.addPreprocessor(template, function(template, args)
Blueprint.addPreprocessor(template, function(template, args)
     -- Create a table to store the connections
     -- Clear any process-related fields to ensure they don't get processed
    local connections = {}
     args.process = nil
   
     args.has_previous = nil
    -- Helper function to add a connection if valid
     args.has_next = nil
    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
     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


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

Revision as of 17:44, 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')

-- TEMPORARILY DISABLE ALL PROCESS CONNECTION HANDLING
-- This is a minimal approach to isolate the issue

-- Ensure we skip the process_connection property completely
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

-- Remove all process connection fields from the template
Blueprint.addPreprocessor(template, function(template, args)
    -- Clear any process-related fields to ensure they don't get processed
    args.process = nil
    args.has_previous = nil
    args.has_next = nil
    
    return args
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