More actions
Titles
! colspan="2" class="infobox-subheader" | Not on a character |-
! colspan="2" class="infobox-subheader" |
|-
| Gnoblin | |
|---|---|
| Using the template | |
| Gnoblin | |
|---|---|
| Simple name only | |
local p = {}
function p.processTitle(frame)
local input = frame.args[1] or ""
-- Check if input already looks like a {{Title}} template
if mw.ustring.match(input, "^%s*%{%{%s*[Tt]itle%s*[|}]") then
return input
end
-- Otherwise, expand the template properly
return frame:expandTemplate{
title = "Title",
args = { name = input }
}
end
function p.stripHouse(frame)
local name = frame.args[1]
if not name or name == "" then
name = mw.title.getCurrentTitle().text
end
local prefixes = { "House", "Clan", "Family", "Dynasty" }
for _, prefix in ipairs(prefixes) do
local pattern = "^[" .. mw.ustring.sub(prefix,1,1):lower() .. mw.ustring.sub(prefix,1,1):upper() .. "]" ..
mw.ustring.sub(prefix,2):lower() .. "%s+"
name = mw.ustring.gsub(name, pattern, "")
end
return name
end
function p.unlink(frame)
local text = frame.args[1] or ""
text = mw.ustring.gsub(text, "[%[%]]", "")
return text
end
function p.smartCategory(frame)
local cat = frame.args[1]
if not cat or cat == "" then
return ""
end
-- Build category title
local title = mw.title.new("Category:" .. cat)
-- If category exists, use it
if title and title.exists then
return "[[Category:" .. cat .. "]]"
end
-- Fallback logic for elf subtypes
if mw.ustring.match(cat:lower(), "elf") then
return "[[Category:Elf]]"
end
-- Otherwise, no category
return ""
end
return p