Module:T-TLD

Revision as of 12:02, 28 April 2025 by MarkWD (talk | contribs) (// via Wikitext Extension for VSCode)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:T-TLD/doc

--Module:T-TLD
-- Makes use of ICANNWiki's "Template Blueprint Framework" to render the "TLD" template

local p = {}

-- ==================== Required modules ====================
local Blueprint = require('Module:LuaTemplateBlueprint')
local TemplateHelpers = require('Module:TemplateHelpers')
local ErrorHandling = require('Module:ErrorHandling')
local ConfigRepository = require('Module:ConfigRepository')
local LinkParser = require('Module:LinkParser')

-- Blueprint default: Module-level cache for lazy-loaded modules
local moduleCache = {}

-- Blueprint default: Lazy module loader
local function lazyRequire(moduleName)
    return function()
        if not moduleCache[moduleName] then
            moduleCache[moduleName] = require(moduleName)
        end
        return moduleCache[moduleName]
    end
end

-- Blueprint default: Modules to lazy load
    -- local getTemplateHelpers = lazyRequire('')
local getPunycode = lazyRequire('Module:Punycode')
local getCountryData = lazyRequire('Module:CountryData')
local getSemanticCategoryHelpers = lazyRequire('Module:SemanticCategoryHelpers')

-- ==================== Helper Functions ====================
-- Blueprint default: Create error context for the module
local errorContext = ErrorHandling.createContext("T-TLD")

-- Blueprint default: Helper for extracting semantic values from wiki links
local function extractSemanticValue(fieldValue, fieldName)
    return TemplateHelpers.extractSemanticValue(fieldValue, fieldName, errorContext)
end

-- ================================================================================

-- IMPORTANT! TEMPLATE BLUEPRINT FRAMEWORK INSTRUCTIONS
-- CONTROL OF TEMPLATE FEATURES: THIS LIST SPECIFIES IN AN EXPLICIT MANNER WHAT FEATURES ARE TO BE CALLED/RENDERED BY THE TEMPLATE.
local template = Blueprint.registerTemplate('TLD', {
    features = {
        title = true,
        logo = true,
        fields = true,
        socialMedia = true,
        semanticProperties = true,
        categories = true,
        errorReporting = true,
    }
})

-- Blueprint default: Initialize standard configuration
Blueprint.initializeConfig(template)

-- ================================================================================

-- TEMPLATE-SPECIFIC CALLS AND CODE

-- ELEMENTS GO HERE

-- SPECIAL SEMANTIC MAPPINGS GO HERE

-- IDN detection preprocessor
local function detectIDNStatus(template, args)
    args._idnFlag = false
    if args.idn and args.idn ~= '' then
        args._idnFlag = true
        local puny = getPunycode().toASCII(args.idn)
        args._ascii = puny
    end
    return args
end

-- ================================================================================

-- ==================== Preprocessors ====================
-- Basic preprocessors
Blueprint.addPreprocessor(template, detectIDNStatus)  -- IDN detection
Blueprint.addPreprocessor(template, 'setPageIdField')  -- Blueprint default
-- Blueprint.addPreprocessor(template, 'deriveRegionFromCountry')

-- ==================== Main Render Function ====================
-- Blueprint default: Render
function p.render(frame)
    return ErrorHandling.protect(
        errorContext,
        "render",
        function()
            return template.render(frame)
        end,
        ErrorHandling.getMessage("TEMPLATE_RENDER_ERROR"),
        frame
    )
end

return p