Module:LuaTemplateBlueprint: Difference between revisions

// via Wikitext Extension for VSCode
Tag: Reverted
No edit summary
Tag: Manual revert
Line 14: Line 14:
  *
  *
  * Note on parameter handling:
  * Note on parameter handling:
  * - Template parameters are extracted directly from frame:getParent().args
  * - Template parameters are extracted and normalized by TemplateHelpers.extractArgs()
  * - Arguments are normalized for case-insensitivity using TemplateHelpers.normalizeArgumentCase()
  * - This function handles case-insensitive parameter names for better user experience
  * - Parameters are accessible via args[paramName] regardless of case used in the template
  * - Parameters are accessible via args[paramName] regardless of case used in the template
]]
]]
Line 330: Line 330:
                      
                      
                     -- Render the fields using TemplateStructure
                     -- Render the fields using TemplateStructure
                     local options = template.config.meta and template.config.meta.fieldOptions or {}
                     return TemplateStructure.renderFieldTable(
                   
                        fields,
                    -- Pre-allocate function array
                        template.config.meta and template.config.meta.fieldOptions or {}
                    local blockFunctions = {}
                   
                    -- Generate a single function that returns all field HTML at once
                    table.insert(blockFunctions, function(_, _)
                        -- Pre-allocate output table based on field count
                        local fieldOutput = {}
                       
                        -- Generate all field HTML in one go
                        for i, field in ipairs(fields) do
                            fieldOutput[i] = string.format(
                                TemplateHelpers.FIELD_FORMAT,
                                field.label,
                                field.value
                            )
                        end
                       
                        -- Return concatenated field HTML
                        return table.concat(fieldOutput, "\n")
                    end)
                   
                    -- Use TemplateStructure.render with the function array
                    return TemplateStructure.render(
                        args,
                        {
                            tableClass = options.tableClass or "template-table",
                            tableAttrs = options.tableAttrs or 'cellpadding="2"',
                            blocks = blockFunctions
                        },
                        template._errorContext
                     )
                     )
                 end,
                 end,
Line 378: Line 349:
                 'StandardBlock_socialMedia',
                 'StandardBlock_socialMedia',
                 function()
                 function()
                    -- Use the SocialMedia module directly
                     return TemplateHelpers.renderSocialMediaBlock(
                    local SocialMedia = require('Module:SocialMedia')
                        args,
                     return SocialMedia.render(args)
                        template.config.meta and template.config.meta.socialMediaOptions or {}
                    )
                 end,
                 end,
                 '',
                 '',
Line 931: Line 903:
     local htmlIndex = 1
     local htmlIndex = 1
     for property, value in pairs(propertyMapping) do
     for property, value in pairs(propertyMapping) do
        -- Use setSemanticProperties with appropriate structure
         propertyHtml[htmlIndex] = SemanticAnnotations.setSemanticProperty(property, value)
        local propertyMapping = {[property] = value}
         propertyHtml[htmlIndex] = SemanticAnnotations.setSemanticProperties(
            {}, -- Empty args table since we're providing the mapping directly
            propertyMapping,
            {} -- Empty options
        )
         htmlIndex = htmlIndex + 1
         htmlIndex = htmlIndex + 1
     end
     end
Line 956: Line 922:
                 for property, value in pairs(providerResult) do
                 for property, value in pairs(providerResult) do
                     if value and value ~= '' then
                     if value and value ~= '' then
                        -- Use setSemanticProperties with appropriate structure
                         propertyHtml[htmlIndex] = SemanticAnnotations.setSemanticProperty(property, value)
                        local propertyMapping = {[property] = value}
                         propertyHtml[htmlIndex] = SemanticAnnotations.setSemanticProperties(
                            {}, -- Empty args table since we're providing the mapping directly
                            propertyMapping,
                            {} -- Empty options
                        )
                         htmlIndex = htmlIndex + 1
                         htmlIndex = htmlIndex + 1
                     end
                     end
Line 1,071: Line 1,031:
     end
     end
      
      
     -- Extract arguments directly from frame (following established pattern)
     -- Extract and normalize arguments
     local args = frame:getParent().args or {}
     local args = TemplateHelpers.extractArgs(frame)
   
    -- Normalize arguments for case-insensitivity
    args = TemplateHelpers.normalizeArgumentCase(args)
      
      
     -- Run preprocessors
     -- Run preprocessors