Module:TemplateFieldProcessor: Difference between revisions

// via Wikitext Extension for VSCode
// via Wikitext Extension for VSCode
 
(8 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
* - Declarative list generation via the `field.list` property
]]
]]


Line 24: Line 19:
local LinkParser = require('Module:LinkParser')
local LinkParser = require('Module:LinkParser')
local NormalizationText = require('Module:NormalizationText')
local NormalizationText = require('Module:NormalizationText')
local ListGeneration = require('Module:ListGeneration')


-- Module-level caches for expensive operations
-- Module-level caches for expensive operations
Line 157: 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 180: Line 169:
         -- Default single-date formatting
         -- 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 222: Line 206:
         return EMPTY_STRING
         return EMPTY_STRING
     end
     end
 
   
     -- Declarative list generation
     -- Wiki Link Handling Strategy: preserveWikiLinks prevents stripping of wiki links
     if field.list then
     local sanitizeOptions = {
        local options = {}
         preserveWikiLinks = field.autoWikiLink or field.preserveWikiLinks
         if type(field.list) == 'string' then
     }
            options.mode = field.list
        elseif type(field.list) == 'table' then
            for k, v in pairs(field.list) do
                options[k] = v
            end
        end
 
        if field.autoWikiLink then
            local originalHook = options.itemHook
            options.itemHook = function(item)
                if type(originalHook) == 'function' then
                    item = originalHook(item)
                end
                -- Ensure the item is a string before wrapping
                local itemContent = type(item) == 'table' and item.content or item
                if itemContent and itemContent ~= '' then
                    local link = '[[' .. itemContent .. ']]'
                    if type(item) == 'table' then
                        item.content = link
                        return item
                    else
                        return link
                    end
                end
                return item
            end
        end
       
        return ListGeneration.createList(value, options)
     end
      
      
     -- Wiki Link Handling Strategy: preserveWikiLinks prevents stripping of wiki links
     -- Wiki Link Handling Strategy: preserveWikiLinks prevents stripping of wiki links