Module:T-Campaign: Difference between revisions
// via Wikitext Extension for VSCode Tags: Manual revert Reverted |
// via Wikitext Extension for VSCode Tags: Manual revert Reverted |
||
| Line 44: | Line 44: | ||
template.config.blocks = template.config.blocks or {} | template.config.blocks = template.config.blocks or {} | ||
-- Helper function: Check for "not applicable" values | |||
local function isNotApplicable(value) | |||
if not value or type(value) ~= "string" then | |||
return false | |||
end | |||
local lowerVal = value:lower():match("^%s*(.-)%s*$") | |||
return lowerVal == "n/a" or lowerVal == "na" or lowerVal == "none" or lowerVal == "no" or lowerVal == "false" | |||
end | |||
-- Helper function: Tokenize semicolon-separated strings for instructions | -- Helper function: Tokenize semicolon-separated strings for instructions | ||
| Line 89: | Line 98: | ||
-- Use JSON config or fallback to default instruction text | -- Use JSON config or fallback to default instruction text | ||
local headerText = (campaignData.instructions and campaignData.instructions.header_text) | local headerText = (campaignData.instructions and campaignData.instructions.header_text) | ||
or "'''READ CAREFULLY'''. These are temporary instructions that will appear only until all parameters outlined here have been filled. Choose 'Edit source' at any time and edit the code below if it already exists. It can also be added manually to any page:" | or "'''READ CAREFULLY'''. These are temporary instructions that will appear only until all parameters outlined here have been filled with data or have 'N/A' in them if the field is not applicable. Choose 'Edit source' at any time and edit the code below if it already exists. It can also be added manually to any page:" | ||
local parameterIntro = (campaignData.instructions and campaignData.instructions.parameter_intro) | local parameterIntro = (campaignData.instructions and campaignData.instructions.parameter_intro) | ||
| Line 263: | Line 272: | ||
-- Generic field processor that handles different data types | -- Generic field processor that handles different data types | ||
local function processFieldValue(value, fieldType) | local function processFieldValue(value, fieldType) | ||
if isNotApplicable(value) then | |||
return nil | |||
end | |||
if type(value) == "table" then | if type(value) == "table" then | ||
if #value > 0 then | if #value > 0 then | ||
| Line 286: | Line 299: | ||
for item in value:gmatch("[^;]+") do | for item in value:gmatch("[^;]+") do | ||
local trimmed = item:match("^%s*(.-)%s*$") -- trim whitespace | local trimmed = item:match("^%s*(.-)%s*$") -- trim whitespace | ||
if trimmed and trimmed ~= "" then | if trimmed and trimmed ~= "" and not isNotApplicable(trimmed) then | ||
table.insert(items, '<span class="campaign-token">' .. trimmed .. '</span>') | table.insert(items, '<span class="campaign-token">' .. trimmed .. '</span>') | ||
end | end | ||
| Line 293: | Line 306: | ||
return table.concat(items, ' ') | return table.concat(items, ' ') | ||
else | else | ||
return | return nil -- Return nil if all items were "not applicable" | ||
end | end | ||
else | else | ||