Jump to content

Module:ConfigRepository

Revision as of 03:41, 10 April 2025 by MarkWD (talk | contribs) (// via Wikitext Extension for VSCode)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:ConfigRepository/doc

-- Module:ConfigRepository
-- Central repository for template configurations that works with TemplateHelpers
-- This module acts as a single source of truth for configurations across all templates

local p = {}

-- Store all template configurations in this table
p.templates = {
    -- Event template configuration
    Event = {
        meta = {
            description = "Module for rendering Event templates with automatic event navigation"
        },
        
        constants = {
            -- Default date formats
            dateFormats = {
                display = "%d %B %Y", -- e.g., "15 March 2025"
                semantic = "%Y-%m-%d"  -- ISO format for semantic properties
            }
        },
        
        patterns = {
            -- Patterns for event navigation detection
            seriesNumber = "^([%w%s]+)%s+(%d+)$",     -- e.g., "ICANN 76"
            seriesYear = "^([%w%s]+)%s+(%d%d%d%d)$",  -- e.g., "IGF 2023"
            
            -- Patterns for multi-value fields
            itemDelimiter = ";%s*",                   -- Semicolon delimiter for lists
            dateRange = "(%d%d?%s+%w+%s+%d%d%d%d)"    -- Date pattern for ranges
        },
        
        fields = {
            {key="logo", label="Logo"},
            {key="process", label="Process"},
            {key="start", label="Start Date"},
            {key="end", label="End Date"},
            {key="region", label="Region"},
            {keys={"country", "territory"}, label="Country"},
            {key="city", label="City"},
            {key="venue", label="Venue"},
            {key="organizer", label="Organizer"},
            {keys={"website", "url"}, label="Website"},
            {keys={"subject", "category"}, label="Subject"}
        },
        
        semantics = {
            -- Property mappings (semantic property to template field)
            properties = {
                ["Has event start date"] = "start",
                ["Has event end date"] = "end",
                ["Part of process"] = "process",
                -- "Has country" and "Has ICANN region" handled by CountryData.addCountrySemanticProperties
                ["Has city"] = "city",
                ["Has venue"] = "venue",
                ["Has event organizer"] = "organizer"
                -- "Has event subject" temporarily removed
            },
            
            -- Additional properties for special cases
            additionalProperties = {
                ["Has country"] = {"country", "territory"}
                -- "Has event subject" temporarily removed
            },
            
            -- Transformation functions for properties
            transforms = {
                ["Has event start date"] = function(value)
                    return tostring(require('Module:DateNormalization').formatDate(value))
                end,
                ["Has event end date"] = function(value)
                    return tostring(require('Module:DateNormalization').formatDate(value))
                end
            }
        }
    }
}

-- Get configuration for a specific template type
function p.getConfig(templateType)
    return p.templates[templateType] or {}
end

-- Get a standard config object for use with existing template modules
-- This integrates with TemplateHelpers.createStandardConfig
function p.getStandardConfig(templateType, customOverrides)
    local TemplateHelpers = require('Module:TemplateHelpers')
    
    -- Get the base configuration
    local baseConfig = p.getConfig(templateType)
    
    -- Create a standard config using TemplateHelpers
    return TemplateHelpers.createStandardConfig(baseConfig, customOverrides)
end

return p