Module:TemplateFieldProcessor: Difference between revisions
// via Wikitext Extension for VSCode Tag: Reverted |
// via Wikitext Extension for VSCode |
||
| (19 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
--[[ | --[[ | ||
* Name: TemplateFieldProcessor | |||
* Author: Mark W. Datysgeld | |||
* Description: Field processing functionality for templates with processor initialization, caching, and error handling | |||
* 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 | |||
]] | ]] | ||
| Line 73: | Line 69: | ||
-- ========== Field Value Management ========== | -- ========== Field Value Management ========== | ||
-- Get field value from args | -- Get field value from args (delegated to TemplateHelpers) | ||
-- @param field table The field definition | -- @param field table The field definition | ||
-- @param args table The template arguments | -- @param args table The template arguments | ||
| Line 81: | Line 77: | ||
return nil | return nil | ||
end | end | ||
local _, value = TemplateHelpers.getFieldValue(args, field) | local _, value = TemplateHelpers.getFieldValue(args, field) | ||
return value | return value | ||
| Line 132: | 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 158: | Line 151: | ||
identity = function(value, args, template) | identity = function(value, args, template) | ||
return value | return value | ||
end, | end, | ||
| Line 170: | 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) | ||
-- | -- 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, | end, | ||
| Line 216: | 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 | ||