Module:ElementTLDFlair: Difference between revisions

// via Wikitext Extension for VSCode
 
// via Wikitext Extension for VSCode
 
(12 intermediate revisions by the same user not shown)
Line 1: Line 1:
--[[  
--[[
* Module:ElementTLDFlair
* Name: ElementTLDFlair
* Renders a flair element for TLD styling based on type, subtype, and IDN.
* Author: Mark W. Datysgeld
* Designed for integration with the Blueprint template system.
* Description: Element module that renders visual flair elements for TLD styling based on type, subtype, and IDN status
]]
* Notes: Designed for Blueprint template system integration; builds CSS classes from TLD properties; uses CanonicalForms for subtype mapping; differentiates IDN ccTLDs and gTLDs; styled via CSS pseudo-elements; protected execution with error handling
]]


local p = {}
local p = {}


p.elementName = "tldflair"
p.elementName = "tldflair"
local ErrorHandling = require('Module:ErrorHandling')
local CanonicalForms = require('Module:CanonicalForms')


-- Create a badge block for TLD styling
-- Create a badge block for TLD styling
Line 15: Line 18:
         -- Protected execution wrapper
         -- Protected execution wrapper
         local function execute(func, ...)
         local function execute(func, ...)
             if errorContext and errorContext.protect then
             if errorContext then
                 return errorContext.protect(
                 return ErrorHandling.protect(
                     errorContext,
                     errorContext,
                     "ElementBlock_tldflair",
                     "ElementBlock_tldflair",
Line 30: Line 33:


         return execute(function()
         return execute(function()
             local tldType   = args.tld_type or ""
            -- Get TLD type: prefer preprocessor-normalized _type, fall back to raw tld_type
             local subtype   = args.tld_subtype or ""
             local tldType = args._type or args.tld_type or ""
             local isIDN     = args._idnFlag
             local subtype = args.tld_subtype or ""
             local punycode = args.ascii or ""
             local isIDN   = (args.idn == "true")
             local punycode = args.ascii or ""


             -- Build CSS class list
             -- Build CSS class list
             local classes = { "tldflair" }
             local classes = { "tld-flair" }
             if tldType ~= "" then
              
                table.insert(classes, "tldflair-type-" .. string.lower(tldType))
            -- Add subtype class if present
            end
             if subtype ~= "" then
             if subtype ~= "" then
                 local sub = string.lower(subtype):gsub("%s+", "")
                 local _, css = CanonicalForms.normalize(subtype, template.config.mappings.tld_subtype)
                 table.insert(classes, "tldflair-subtype-" .. sub)
                 if css then
                    table.insert(classes, css)
                end
             end
             end
           
            -- Add IDN class if applicable
             if isIDN then
             if isIDN then
                 table.insert(classes, "tldflair-idn")
                -- Normalize the type if it hasn't been normalized yet
                local normalizedType = tldType
                if tldType ~= "" and tldType ~= "gTLD" and tldType ~= "ccTLD" then
                    normalizedType = select(1, CanonicalForms.normalize(tldType, template.config.mappings.tld_type)) or tldType
                end
               
                local idnClass = (normalizedType == "ccTLD") and "tld-template-idn-cctld" or "tld-template-idn-gtld"
                 table.insert(classes, idnClass)
            -- Otherwise, if no subtype, add base type class for non-IDN TLDs
            elseif subtype == "" and tldType ~= "" then
                -- Normalize the type if it hasn't been normalized yet
                local normalizedType = tldType
                if tldType ~= "gTLD" and tldType ~= "ccTLD" then
                    normalizedType = select(1, CanonicalForms.normalize(tldType, template.config.mappings.tld_type)) or tldType
                end
               
                local typeClass = (normalizedType == "ccTLD") and "tld-template-cctld" or "tld-template-gtld"
                table.insert(classes, typeClass)
             end
             end
           
             local classAttr = table.concat(classes, " ")
             local classAttr = table.concat(classes, " ")


             -- Determine display text
             -- Determine display text (styled via CSS pseudo-element)
             local display = tldType
             local display = ""
            if isIDN and punycode ~= "" then
                display = punycode
            end


             -- Render as a table row
             -- Render as a table row
            local output = {
local output = {
                "|-",
    "|-",
                '| colspan="2" class="' .. classAttr .. '" | ' .. display
    '! colspan="2" class="' .. classAttr .. '" | ' .. display
            }
}
             return table.concat(output, "\n")
             return table.concat(output, "\n")
         end)
         end)