Module:LuaTemplateBlueprint: Difference between revisions

// via Wikitext Extension for VSCode
// via Wikitext Extension for VSCode
Line 846: Line 846:
      
      
     return template
     return template
end
-- Process a value using a transform function
-- @param value string The value to transform
-- @param property string The property name (for error context)
-- @param transform function The transform function
-- @param args table The template arguments
-- @param template table The template object
-- @return string The transformed value
local function applyTransform(value, property, transform, args, template)
    if not value or value == '' then
        return ''
    end
   
    if not transform then
        return value
    end
   
    local transformedValue = p.protectedExecute(
        template,
        'Transform_' .. property,
        function() return transform(value, args, template) end,
        value,
        value,
        args,
        template
    )
   
    return transformedValue or ''
end
end


-- Validate property value to prevent SMW parser issues
-- Validate property value to prevent SMW parser issues
-- @param value string The value to validate
-- @param value string The value to validate
-- @param property string The property name (for context)
-- @return string The validated value
-- @return string The validated value
local function validatePropertyValue(value, property)
local function validatePropertyValue(value)
     if not value or value == '' then
     if not value or value == '' then
         return ''
         return ''
Line 897: Line 867:
      
      
     return value
     return value
end
-- Property deduplication helper
-- Maintains a signature-based deduplication system
-- @param collector table The collector object with seen and properties tables
-- @param property string The property name
-- @param value string The property value
local function deduplicateProperty(collector, property, value)
    if not value or value == '' then return end
   
    -- Validate the value first
    value = validatePropertyValue(value, property)
    if value == '' then return end
   
    -- Create signature for this property-value pair
    local signature = property .. ":" .. tostring(value)
   
    -- Initialize collector structure if needed
    collector.seen = collector.seen or {}
    collector.properties = collector.properties or {}
    collector.count = collector.count or 0
   
    -- Skip if we've seen this exact property-value pair
    if collector.seen[signature] then return end
   
    -- Mark as seen
    collector.seen[signature] = true
    collector.count = collector.count + 1
   
    -- Add to properties
    if not collector.properties[property] then
        collector.properties[property] = value
    else
        -- Convert to array if needed
        if type(collector.properties[property]) ~= "table" then
            collector.properties[property] = {collector.properties[property]}
        end
        -- Add unique value
        table.insert(collector.properties[property], value)
    end
end
end