Module:TemplateFieldProcessor: Difference between revisions

// via Wikitext Extension for VSCode
// via Wikitext Extension for VSCode
 
(17 intermediate revisions by the same user not shown)
Line 1: Line 1:
--[[
--[[
* TemplateFieldProcessor.lua
* Name: TemplateFieldProcessor
* Provides field processing functionality for ICANNWiki templates
* Author: Mark W. Datysgeld
*
* Description: Field processing functionality for templates with processor initialization, caching, and error handling
* This module handles the processing of template fields, including:
* Notes: Standard field processors for common field types; processor initialization and caching; field value retrieval; field processing with error handling; declarative list generation via field.list property; includes wiki link handling strategy
* - Standard field processors for common field types
* - Processor initialization and caching
* - Field value retrieval
* - Field processing with error handling
]]
]]


Line 128: Line 124:


-- Get processor for a field
-- Get processor for a field
-- Internal helper function: determines which processor to use for a field; called by processField to select the appropriate processor based on field configuration
-- @param processors table The processors table
-- @param processors table The processors table
-- @param field table The field definition
-- @param field table The field definition
Line 154: Line 151:
     identity = function(value, args, template)
     identity = function(value, args, template)
         return value
         return value
    end,
   
    -- Website processor
    website = function(value, args, template)
        return TemplateHelpers.normalizeWebsites(value)
     end,
     end,
      
      
Line 166: Line 158:
     end,
     end,
      
      
     -- Date processor
     -- Date processor (joins start and ending dates for Event templates)
     date = function(value, args, template)
     date = function(value, args, template)
         -- Uses date format configuration from ConfigRepository with lazy loading
         -- For Event templates, if an ending date exists, render a range
        if template and template.type == 'Event' then
            local endValue = args['ending'] or args['end']
            if endValue and endValue ~= '' then
                return TemplateHelpers.formatDateRange(value, endValue, {outputMode="complete"})
            end
        end
        -- Default single-date formatting
         return getNormalizationDate().formatDate(value)
         return getNormalizationDate().formatDate(value)
    end,
   
    -- Language processor
    language = function(value, args, template)
        return TemplateHelpers.normalizeLanguages(value)
     end,
     end,
      
      
Line 212: Line 206:
         return EMPTY_STRING
         return EMPTY_STRING
     end
     end
   
    -- Wiki Link Handling Strategy: preserveWikiLinks prevents stripping of wiki links
    local sanitizeOptions = {
        preserveWikiLinks = field.autoWikiLink or field.preserveWikiLinks
    }
      
      
     -- Wiki Link Handling Strategy: preserveWikiLinks prevents stripping of wiki links
     -- Wiki Link Handling Strategy: preserveWikiLinks prevents stripping of wiki links