FANDOM


 
local moduleIcon = {}
 
local iconData = require('module:Icon/data')
 
local errors = {
    ['iconDoesntExist'] = function(name)
        return '<span style=\'color:red;font-weight:normal;\'>Icon <span style=\'font-weight:bold;\'>'..name..'</span> doesn\'t exist!</span>[[Category:Nonexistent icon]]'
    end
}
 
function exists(str)
    return str ~= nil and str ~= ""
end
 
function moduleIcon.icon(frame)
    local iconName = frame.args[1]
    local text = frame.args[2]
    local size = frame.args.size
    local link = frame.args.link
    local linkOnly = frame.args.linkOnly
 
    if (iconData[iconName] == nil) then
        return errors['iconDoesntExist'](iconName)
    end
 
    if (not exists(linkOnly)) then
        link = iconData[iconName]['link']
    end
 
    if (exists(linkOnly)) then
        if (text ~= nil and text ~= "") then
            return "[["..link.."|"..text.."]]"
        else 
            return "[["..link.."]]"
        end
    end
 
    if (not exists(size)) then
        size = iconData[iconName]['size'] 
    end
 
    return createIcon(iconData[iconName]['image'], text, size, link)
 
end
 
function createIcon(icon, text, size, link)
    local iconString = '[[File:'..icon..'|'..size..'|link='..link..']]'
 
    if (exists(text)) then
        iconString = iconString .. ' [['..link..'|'..text..']]'    
    end
 
    return iconString
end
 
function moduleIcon.thumb(frame)
    local iconName = frame.args.icon
    local size = frame.args.size
    local link = frame.args.link
    local description = frame.args.description
 
    if (iconData[iconName] == nil) then
        return errors['iconDoesntExist'](iconName)
    end
 
    return createThumbnail(iconData[iconName]['image'], size, link, description)
end
 
function createThumbnail(icon, size, link, description)
    local thumb = '[[File:'..icon..'|thumb'
    if (exists(size)) then
        thumb = thumb..'|'..size
    end
 
    if (exists(description)) then
        thumb = thumb..'|'..description
    end
 
    if (exists(link)) then
        thumb = thumb..'|link='..link
    end
 
    return thumb..']]'
end
 
return moduleIcon

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.