Module:ElementTLDFlair: Difference between revisions
// via Wikitext Extension for VSCode |
// via Wikitext Extension for VSCode |
||
| (9 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 9: | Line 10: | ||
p.elementName = "tldflair" | p.elementName = "tldflair" | ||
local ErrorHandling = require('Module:ErrorHandling') | 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 31: | 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 = { " | local classes = { "tld-flair" } | ||
-- Add subtype class if present | |||
if subtype ~= "" then | if subtype ~= "" then | ||
local | local _, css = CanonicalForms.normalize(subtype, template.config.mappings.tld_subtype) | ||
table.insert(classes, | if css then | ||
table.insert(classes, css) | |||
end | |||
end | end | ||
-- Add IDN class if applicable | |||
if isIDN then | if isIDN then | ||
table.insert(classes, " | -- 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 | local display = "" | ||
-- Render as a table row | -- Render as a table row | ||