Module:T-CountryHub: Difference between revisions

// via Wikitext Extension for VSCode
// via Wikitext Extension for VSCode
Line 146: Line 146:
     'intro',
     'intro',
     'overview',
     'overview',
     -- The data blocks are now rendered inside the custom render function
     'dataColumns',
     'wrapperClose',
     'wrapperClose',
     'categories',
     'categories',
Line 472: Line 472:
         return renderSection('resources:' .. args.has_country, params, {'Resources'})
         return renderSection('resources:' .. args.has_country, params, {'Resources'})
     end,
     end,
}
-- Data columns "super block"
template.config.blocks.dataColumns = {
    feature = 'fullPage',
    render = function(template, args)
        local dataBlocks = {}
        local dataBlockNames = {
            'organizations', 'people', 'laws', 'documents',
            'geoTlds', 'meetings', 'nra', 'resources'
        }
        for _, blockName in ipairs(dataBlockNames) do
            -- We need to check if the feature for the block is enabled before rendering
            if template.features[blockName] then
                local blockContent = template:renderBlock(blockName, args)
                if blockContent and blockContent ~= '' then
                    table.insert(dataBlocks, blockContent)
                end
            end
        end
        if #dataBlocks == 0 then
            return ''
        end
        local columns = {'', '', ''}
        for i, blockContent in ipairs(dataBlocks) do
            local colIndex = (i - 1) % 3 + 1
            columns[colIndex] = columns[colIndex] .. blockContent
        end
        local dataContainer = html.create('div'):addClass('country-hub-data-container')
        for _, colContent in ipairs(columns) do
            if colContent ~= '' then
                dataContainer:tag('div'):addClass('country-hub-column'):wikitext(colContent):done()
            end
        end
       
        return tostring(dataContainer)
    end
}
}


Line 507: Line 548:
     return cats
     return cats
end)
end)
-- Custom render function to handle column distribution
local original_render = template.render
function template:render(frame)
    local args = self:processFrame(frame)
    local content = {}
    local dataBlocks = {}
    local dataBlockNames = {
        'organizations', 'people', 'laws', 'documents',
        'geoTlds', 'meetings', 'nra', 'resources'
    }
    local dataBlockSet = {}
    for _, name in ipairs(dataBlockNames) do
        dataBlockSet[name] = true
    end
    -- Render non-data blocks and collect data blocks
    for _, blockName in ipairs(self.config.blockSequence) do
        if dataBlockSet[blockName] then
            local blockContent = self:renderBlock(blockName, args)
            if blockContent and blockContent ~= '' then
                table.insert(dataBlocks, blockContent)
            end
        else
            table.insert(content, self:renderBlock(blockName, args))
        end
    end
    -- Distribute data blocks into columns
    if #dataBlocks > 0 then
        local columns = {'', '', ''}
        for i, blockContent in ipairs(dataBlocks) do
            local colIndex = (i - 1) % 3 + 1
            columns[colIndex] = columns[colIndex] .. blockContent
        end
        local dataContainer = html.create('div'):addClass('country-hub-data-container')
        for _, colContent in ipairs(columns) do
            if colContent ~= '' then
                dataContainer:tag('div'):addClass('country-hub-column'):wikitext(colContent):done()
            end
        end
        -- Insert the data container before the wrapperClose block
        table.insert(content, #content - 2, tostring(dataContainer))
    end
    return table.concat(content)
end


-- Render entry point; wraps the Blueprint rendering process with error protection
-- Render entry point; wraps the Blueprint rendering process with error protection