Module:MasonryLayout: Difference between revisions
// via Wikitext Extension for VSCode |
// via Wikitext Extension for VSCode |
||
| Line 511: | Line 511: | ||
return table.concat(classes, ' ') | return table.concat(classes, ' ') | ||
end | |||
-- ========== Intelligent Layout Rendering ========== | |||
-- Main render function for intelligent masonry layout | |||
-- This is the core function that coordinates content rendering, analysis, and distribution | |||
-- @param template table Template object with features and configuration | |||
-- @param args table Template arguments | |||
-- @param config table Configuration with cardDefinitions, options, and blockRenderers | |||
-- @return string Complete masonry layout HTML | |||
function p.renderIntelligentLayout(template, args, config) | |||
-- Create render-time error context (Blueprint pattern) | |||
local errorContext = ErrorHandling.createContext("MasonryLayout") | |||
return ErrorHandling.protect( | |||
errorContext, | |||
"renderIntelligentLayout", | |||
function() | |||
return p.renderIntelligentLayoutInternal(template, args, config, errorContext) | |||
end, | |||
EMPTY_STRING, | |||
template, args, config | |||
) | |||
end | |||
-- Internal implementation of intelligent layout rendering | |||
-- @param template table Template object | |||
-- @param args table Template arguments | |||
-- @param config table Configuration object | |||
-- @param errorContext table Error context for protected operations | |||
-- @return string Complete masonry layout HTML | |||
function p.renderIntelligentLayoutInternal(template, args, config, errorContext) | |||
local cardDefinitions = config.cardDefinitions or {} | |||
local options = config.options or {} | |||
local blockRenderers = config.blockRenderers or {} | |||
local columnCount = options.columns or DEFAULT_COLUMNS | |||
-- Build cards with render-time content generation | |||
local cards = {} | |||
local cardIndex = 1 | |||
for _, cardDef in ipairs(cardDefinitions) do | |||
-- Check if this card's feature is enabled | |||
if template.features[cardDef.feature] then | |||
-- Get the block renderer for this card | |||
local renderer = blockRenderers[cardDef.blockId] | |||
if renderer and renderer.render then | |||
-- Render the card content at render-time (not configuration-time) | |||
local cardContent = ErrorHandling.protect( | |||
errorContext, | |||
"renderCard_" .. cardDef.blockId, | |||
function() | |||
return renderer.render(template, args) | |||
end, | |||
EMPTY_STRING, | |||
template, args | |||
) | |||
if cardContent and cardContent ~= EMPTY_STRING then | |||
-- Analyze the content for size estimation | |||
local cardData = p.analyzeCardContent(cardContent, cardDef) | |||
cardData.id = cardDef.blockId | |||
cardData.title = cardDef.title or cardDef.blockId | |||
cardData.content = cardContent | |||
cardData.estimatedSize = p.estimateCardSize(cardData, options) | |||
cards[cardIndex] = cardData | |||
cardIndex = cardIndex + 1 | |||
end | |||
end | |||
end | |||
end | |||
-- Distribute cards across columns | |||
local distribution = p.distributeCards(cards, columnCount) | |||
-- Render the complete masonry layout | |||
local containerClass = options.containerClass or 'country-hub-masonry-container' | |||
local masonryHtml = string.format('<div class="%s">', containerClass) | |||
masonryHtml = masonryHtml .. p.renderDistributedLayout(distribution, options) | |||
masonryHtml = masonryHtml .. '</div>' | |||
return masonryHtml | |||
end | end | ||