Module:ElementTLDFlair: Difference between revisions
// via Wikitext Extension for VSCode |
// via Wikitext Extension for VSCode |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
--[[ | --[[ | ||
* Name: ElementTLDFlair | |||
* Author: Mark W. Datysgeld | |||
* 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 = {} | ||
| Line 32: | Line 33: | ||
return execute(function() | return execute(function() | ||
local tldType | -- Get TLD type: prefer preprocessor-normalized _type, fall back to raw tld_type | ||
local subtype | local tldType = args._type or args.tld_type or "" | ||
local isIDN | local subtype = args.tld_subtype or "" | ||
local punycode | local isIDN = (args.idn == "true") | ||
local punycode = args.ascii or "" | |||
-- Build CSS class list | -- Build CSS class list | ||
local classes = { "tld-flair" } | local classes = { "tld-flair" } | ||
-- Add subtype class if present | |||
if subtype ~= "" then | if subtype ~= "" then | ||
local _, css = CanonicalForms.normalize(subtype, template.config.mappings.tld_subtype) | local _, css = CanonicalForms.normalize(subtype, template.config.mappings.tld_subtype) | ||
| Line 45: | Line 49: | ||
end | end | ||
end | end | ||
-- Add IDN class if applicable | |||
if isIDN then | if isIDN then | ||
local idnClass = | -- 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) | 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, " ") | ||