Module:LuaTemplateBlueprint: Difference between revisions

// via Wikitext Extension for VSCode
// via Wikitext Extension for VSCode
Line 986: Line 986:
     end
     end
      
      
     -- Process additional properties with transforms
     -- Process additional properties with early deduplication and multi-value handling
     for property, fields in pairs(additionalProperties) do
     for property, fields in pairs(additionalProperties) do
         -- Skip properties that are explicitly marked to skip
         -- Skip properties that are explicitly marked to skip
Line 994: Line 994:
                 local rawValue = args[fieldName]
                 local rawValue = args[fieldName]
                 if rawValue and rawValue ~= '' then
                 if rawValue and rawValue ~= '' then
                     local transformed = applyTransform(rawValue, property, transform, args, template)
                    -- Handle multi-value fields by splitting first
                     if transformed and transformed ~= '' then
                     local values
                         local existing = allProperties[property]
                     if rawValue:find(';') then
                        if existing == nil then
                         values = TemplateHelpers.splitMultiValueString(rawValue)
                            allProperties[property] = transformed
                    else
                         else
                         values = {rawValue}
                            if type(existing) ~= "table" then
                    end
                                allProperties[property] = { existing }
                   
                            end
                    -- Process each value individually through deduplication
                            -- Add only if not already present
                    for _, singleValue in ipairs(values) do
                            local found = false
                        local trimmedValue = singleValue:match("^%s*(.-)%s*$")
                            for _, v in ipairs(allProperties[property]) do
                        if trimmedValue and trimmedValue ~= '' then
                                if v == transformed then
                            local transformed = applyTransform(trimmedValue, property, transform, args, template)
                                    found = true
                             if transformed and transformed ~= '' then
                                    break
                                 deduplicateProperty(collector, property, transformed)
                                end
                            end
                             if not found then
                                 table.insert(allProperties[property], transformed)
                             end
                             end
                         end
                         end