Naruto Fanon Wiki
Advertisement

Documentation for this module may be created at Module:Infobox/doc

local infobox = {}
 
local function ucfirst(name)
    return string.gsub(name, "^%l", string.upper)
end
 
function infobox.icon(frame)
    local args = frame:getParent().args
    local name = mw.ustring.lower(args[1])
    local type = args[2] or args["Icon Type"]
    local size = args.size or "18"
    local link = args.link or args[1] or ""
    local text = args.text or ""
 
    if not name then return "" end
    name = string.gsub(string.gsub(name, "ū", "u"), "ō", "o") -- Fix macrons
 
    if type == "Gender" then
        return string.format("[[File:Gender %s.svg|%spx|link=]]", string.gsub(name, "^%l", string.upper), size)
    end
 
    if type == "Astrological Sign" then
        return string.format("[[File:Astrological Sign "..frame:expandTemplate{ title = 'Astrological Sign', args = { name } }..".svg|%spx|link=]]", size)
    end
 
    if type == "Ninja rank" then
        if name == "genin" then
            return string.format("[[File:Genin Symbol.svg|%spx|link=%s|%s]]", size, link, text)
        end
        if name == "chunin" then
            return string.format("[[File:Chunnin Symbol.svg|%spx|link=%s|%s]]", size, link, text)
        end
        if name == "jonin" then
            return string.format("[[File:Jounin Symbol.svg|%spx|link=%s|%s]]", size, link, text)
        end
    end
 
    -- Load the table of icons
    local icons = mw.loadData('Module:Infobox/icons')
 
    if type == "Kekkei Genkai" or type == "Nature" then 
        name = string.gsub(name, " release$", "")
 
        if icons[name] == nil then
            local n = "Nature Icon "..mw.text.split(ucfirst(name), " ")[1]..".svg"
            if mw.title.new("File:"..n).exists then
                return (
                    string.format("[[File:%s|%spx|link=%s|%s]]", n, size, link, text) ..
                    frame:preprocess("{{#set:Infobox Icon="..n.."}}").."[[Category:Infoboxes using unknown icon]]"
                )
            end
        else return string.format("[[%s|%spx|link=%s|%s]]", icons[name], size, link, text)
        end
    end
 
    if type == "Ninja clan" then 
        name = string.gsub(name, " clan$", "")
 
        if icons[name] == nil then
            local n = mw.text.split(ucfirst(name), " ")[1].." Symbol.svg"
            if mw.title.new("File:"..n).exists then
                return (
                    string.format("[[File:%s|%spx|link=%s|%s]]", n, size, link, text) ..
                    frame:preprocess("{{#set:Infobox Icon="..n.."}}").."[[Category:Infoboxes using unknown icon]]"
                )
            end
        else return string.format("[[%s|%spx|link=%s|%s]]", icons[name], size, link, text)
        end
    end
 
    if type == "Ninja loyalty" or type == "Team" then
 
        if icons[name] == nil then
            local n = args[1].." Symbol.svg"
            if mw.title.new("File:"..n).exists then
                return (
                    string.format("[[File:%s|%spx|link=%s|%s]]", n, size, link, text) ..
                    frame:preprocess("{{#set:Infobox Icon="..n.."}}").."[[Category:Infoboxes using unknown icon]]"
                )
            end
        else return string.format("[[%s|%spx|link=%s|%s]]", icons[name], size, link, text)
        end
    end
    
    if icons[name] ~= nil then
        return string.format("[[%s|%spx|link=%s|%s]]", icons[name], size, link, text)
    end

    return ""
end
return infobox

--[[Category:Lua Modules]]
Advertisement