Module:TemplateHelpers: Difference between revisions

// via Wikitext Extension for VSCode
// via Wikitext Extension for VSCode
Line 392: Line 392:
-- Generates a standard title block with configurable class and text
-- Generates a standard title block with configurable class and text
-- Enhanced to support achievement integration with options
-- Enhanced to support achievement integration with options
-- @deprecated Direct implementation moved to TemplateStructure.lua and AchievementSystem.lua
function p.renderTitleBlock(args, titleClass, titleText, options)
function p.renderTitleBlock(args, titleClass, titleText, options)
     options = options or {}
     options = options or {}
    titleClass = titleClass or "template-title"
      
      
     -- Basic title block without achievement integration
     -- If achievement support is needed, use AchievementSystem
     if not options.achievementSupport then
     if options.achievementSupport then
         return string.format('|-\n! colspan="2" class="%s" | %s', titleClass, titleText)
         local AchievementSystem = require('Module:AchievementSystem')
    end
        local achievementClass = options.achievementClass or ""
   
        local achievementId = options.achievementId or ""
    -- With achievement support
        local achievementName = options.achievementName or ""
    local achievementClass = options.achievementClass or ""
       
    local achievementId = options.achievementId or ""
         return AchievementSystem.renderTitleBlockWithAchievement(
    local achievementName = options.achievementName or ""
             args, titleClass, titleText, achievementClass, achievementId, achievementName
   
    -- Only add achievement attributes if they exist
    if achievementClass ~= "" and achievementId ~= "" then
         return string.format(
             '|-\n! colspan="2" class="%s %s" data-achievement-id="%s" data-achievement-name="%s" | %s',
            titleClass, achievementClass, achievementId, achievementName, titleText
         )
         )
     else
     else
         -- Clean row with no achievement data
         -- Otherwise use the basic title block from TemplateStructure
         return string.format('|-\n! colspan="2" class="%s" | %s', titleClass, titleText)
        local TemplateStructure = require('Module:TemplateStructure')
         return TemplateStructure.renderTitleBlock(args, titleClass, titleText)
     end
     end
end
end
Line 461: Line 456:
     return processedValue
     return processedValue
end
end
-- Module-level cache for property descriptions
local propertyDescriptionCache = {}


-- Get property description from a property page
-- Get property description from a property page
-- @param propertyName string The name of the property (e.g., "Has interview format")
-- @param propertyName string The name of the property (e.g., "Has interview format")
-- @return string|nil The property description or nil if not found
-- @return string|nil The property description or nil if not found
-- @deprecated Direct implementation moved to SemanticCategoryHelpers.lua
function p.getPropertyDescription(propertyName)
function p.getPropertyDescription(propertyName)
     -- Check cache first
     return SemanticCategoryHelpers.getPropertyDescription(propertyName)
    if propertyDescriptionCache[propertyName] ~= nil then
        return propertyDescriptionCache[propertyName]
    end
   
    -- Construct the property page title
    local propertyPageTitle = "Property:" .. propertyName
   
    -- Try to load the property page
    local propertyPage = mw.title.new(propertyPageTitle)
    if not propertyPage or not propertyPage.exists then
        propertyDescriptionCache[propertyName] = nil
        return nil
    end
   
    -- Extract the description from the page content
    local content = propertyPage:getContent()
    if not content then
        propertyDescriptionCache[propertyName] = nil
        return nil
    end
   
    -- Look for the property description in the content
    -- Pattern matches [[Has property description::description text@en]]
    local description = content:match("%[%[Has property description::(.-)@?e?n?%]%]")
    if not description then
        -- Try canonical description as fallback
        description = content:match("'''Canonical description''': (.-)[%.%?!]")
    end
   
    -- Cache the result (even if nil)
    propertyDescriptionCache[propertyName] = description
   
    return description
end
end


Line 609: Line 569:


-- Renders a standard divider block with optional label
-- Renders a standard divider block with optional label
-- @deprecated Direct implementation moved to TemplateStructure.lua
function p.renderDividerBlock(label)
function p.renderDividerBlock(label)
     if label and label ~= "" then
     local TemplateStructure = require('Module:TemplateStructure')
        return string.format('|-\n| colspan="2" class="template-divider" |\n|-\n| colspan="2" class="icannwiki-centered" | <span class="icannwiki-bold">%s</span>', label)
     return TemplateStructure.renderDividerBlock(label)
     else
        return '|-\n| colspan="2" class="template-divider" |'
    end
end
end


Line 722: Line 680:


-- Creates a standardized configuration structure for template modules
-- Creates a standardized configuration structure for template modules
-- @deprecated Direct implementation moved to ConfigRepository.lua
function p.createStandardConfig(config)
function p.createStandardConfig(config)
     config = config or {}
     local ConfigRepository = require('Module:ConfigRepository')
      
     return ConfigRepository.createStandardConfig(config)
    -- Initialize with defaults
    local standardConfig = {
        meta = config.meta or {
            description = "Template module configuration"
        },
        mappings = config.mappings or {},
        fields = config.fields or {},
        semantics = config.semantics or {
            properties = {},
            transforms = {},
            additionalProperties = {}
        },
        constants = config.constants or {},
        patterns = config.patterns or {},
        categories = config.categories or {} -- Add categories field to preserve base categories
    }
   
    return standardConfig
end
end