Module:Storm categories: Difference between revisions

Content deleted Content added
adjust aliases
better demo
Line 459:
icons["stss"] = icons["swiosts"]
icons["tc"] = icons["swiotc"]
 
local customKeys = {}
for k, v in pairs(colors) do
table.insert(customKeys, k)
end
for k, v in pairs(icons) do
table.insert(customKeys, k)
end
TableTools.removeDuplicates(customKeys)
 
function p.color(frame)
return p._color(frame.args[1] or frame:getParent().args[1], false)
end
 
Line 467 ⟶ 476:
return p._name(
frame.args[1] or frame:getParent().args[1],
frame.args[2] or frame:getParent().args[2],
false
)
end
 
function p.sortkey(frame)
return p._sortkey(frame.args[1] or frame:getParent().args[1], false)
end
 
function p.icon(frame)
return p._icon(frame.args[1] or frame:getParent().args[1], false)
end
 
function p._color(colorCode, nullIfMissing)
-- This looks confusing, but it's actually nested ternaries (for nil checks)
local color = (colorCode ~= nil and string.len(colorCode) ~= 0) and
Line 485 ⟶ 495:
or defaultCategory
return colors[color] or ((cats[color] or cats[defaultCategory]).color)(
nullIfMissing
and { color = nil }
or cats[defaultCategory]
)).color)
end
 
function p._name(category, basin, nullIfMissing)
local name_def = (cats[
(category ~= nil and string.len(category) ~= 0) and
Line 498 ⟶ 512:
name_def[string.lower(basin or "default")]
or name_def["default"]
or (nullIfMissing and nil or error("No default name for basin-based category name."))
)
or name_def
end
 
function p._sortkey(category, nullIfMissing)
-- This looks confusing, but it's actually nested ternaries (for nil checks)
return (cats[
Line 509 ⟶ 523:
string.gsub(string.lower(category), "[^%w]", "")
or defaultCategory
] or (nullIfMissing and { sortkey = nil } or cats[defaultCategory])).sortkey
end
 
function p._icon(iconCode, nullIfMissing)
-- This looks confusing, but it's actually nested ternaries (for nil checks)
local icon = (iconCode ~= nil and string.len(iconCode) ~= 0) and
Line 520 ⟶ 534:
return icons[icon] or (cats[icon] ~= nil and (
cats[icon].icon or cats["tropicalcyclone"].icon
) or (nullIfMissing and nil or cats[defaultCategory].icon))
end
 
Line 724 ⟶ 738:
end
for name, color_ in TableTools.sortedPairs(colorsTableTools.listToSet(customKeys)) do
if cats[name] == nil then
local row = mw.html.create("tr")
local icon = p._icon(name, true)
row
:node(mw.html.create("td")
:wikitext("''<span style=\"color:gray\">N/A</span>''"))
icon ~= nil
and icon
:wikitext( or "''<span style=\"color:gray\">not availableN/A</span>''"))
))
:node(mw.html.create("td"):wikitext(name))
:node(mw.html.create("td")
local color = p._color(name, true)
:attr("colspan", "2")
-- Add more conditions eventually
:wikitext("''<span style=\"color:gray\">not available</span>''"))
if cats[name]color =~= nil then
:node(mw.html.create("td")
row
:attr("style", "background-color: #" .. color .. "; padding: 0; width: 1.8em"))
:node(mw.html.create("td")
:wikitextattr("#colspan", .. color)"2")
:wikitext("''<span style=\"color:gray\">not available</span>''"))
:node(mw.html.create("td")
:attrnode(mw.html.create("colspan", "2td")
:wikitextattr("''<span style=\", "background-color:gray\ #">not available</span>''.. color .. "; padding: 0; width: 1.8em"))
out :node(rowmw.html.create("td")
:wikitext("#" .. color))
end
:node(mw.html.create("td")
end
:attr("colspan", "2")
:wikitext("''<span style=\"color:gray\">not available</span>''"))
for name, icon in TableTools.sortedPairs(icons) do
else
if cats[name] == nil then
row
local row = mw.html.create("tr")
:node(mw.html.create("td")
:wikitextattr(icons[name])"colspan", "6")
:wikitext("''<span style=\"color:gray\">not available</span>''"))
:node(mw.html.create("td"):wikitext(name))
end
:node(mw.html.create("td")
:attr("colspan", "6")
:wikitext("''<span style=\"color:gray\">not available</span>''"))
out:node(row)
end