Module:TemplateFieldProcessor: Difference between revisions
// via Wikitext Extension for VSCode Tag: Manual revert |
// via Wikitext Extension for VSCode |
||
| Line 8: | Line 8: | ||
* - Field value retrieval | * - Field value retrieval | ||
* - Field processing with error handling | * - Field processing with error handling | ||
* - Declarative list generation via the `field.list` property | |||
]] | ]] | ||
| Line 23: | Line 24: | ||
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 219: | Line 221: | ||
if not value or value == '' then | if not value or value == '' then | ||
return EMPTY_STRING | return EMPTY_STRING | ||
end | |||
-- Declarative list generation | |||
if field.list then | |||
local options = {} | |||
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 | end | ||