Module:TemplateFieldProcessor: Difference between revisions

// via Wikitext Extension for VSCode
Tag: Reverted
// via Wikitext Extension for VSCode
 
(10 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 155: 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 178: 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 198: Line 184:
     multivalue = function(value, args, template)
     multivalue = function(value, args, template)
         return TemplateHelpers.normalizeMultiValue(value)
         return TemplateHelpers.normalizeMultiValue(value)
    end,
    -- List processor
    list = function(value, args, template, field)
        local ListGeneration = require('Module:ListGeneration')
        local listOptions = field.listOptions or {}
        -- If autoWikiLink is enabled for the field, create an itemHook to apply it
        if field.autoWikiLink then
            listOptions.itemHook = function(item)
                return LinkParser.applyWikiLinkHandling(item, field)
            end
        end
        return ListGeneration.createList(value, listOptions)
     end
     end
}
}
Line 235: 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
Line 248: Line 224:
      
      
     local processor = p.getFieldProcessor(processors, field)
     local processor = p.getFieldProcessor(processors, field)
   
    if processor == processors.identity then
        if sanitizeOptions.preserveWikiLinks then
            return value
        else
            return NormalizationText.sanitizeUserInput(value, nil, nil, sanitizeOptions)
        end
    end
      
      
     -- Use error context if provided
     -- Use error context if provided
Line 268: Line 252:
     local result = protectFunc(
     local result = protectFunc(
         function()
         function()
            -- Pass the field object to the processor
             local processed = processor(value, args)
             local processed = processor(value, args, template, field)
              
              
            -- If the processor is not the list processor, handle wiki link preservation
             if sanitizeOptions.preserveWikiLinks and processed and processed ~= '' then
             if field.processor ~= 'list' and sanitizeOptions.preserveWikiLinks and processed and processed ~= '' then
                 if value:match(WIKI_LINK_PATTERN) and not processed:match(WIKI_LINK_PATTERN) then
                 if value:match(WIKI_LINK_PATTERN) and not processed:match(WIKI_LINK_PATTERN) then
                     return value
                     return value