模块:Iconify

This module depends on the following other modules:
Module:Arguments
Documentation Module:Iconify/doc

This module is similar to {{Iconify}} but for modules.

Parameters

Parameter Description Required Default
icon Text/main file name required none
group image/file "group"/prefix optional none
width Width of the icon
  • If preceded by an 'x', sets height instead of width
optional 24px
text modifies text output if used:
  • link: adds hyperlink to text
  • nosp: removes space between icon and text
  • any other: removes text, i.e. icon only
optional none
mod modifier text between icon and output text
  • Do not combine with nosp in text
optional none
image alternate image file definition optional group icon.png
link alternate link optional icon

Notes icon is made lowercase, changes dashes - to underscores _, and removes any single quotes/apostrophes ' for the file name, however those changes are not made for the text or link usage. group is used exactly as typed, however the first character counts as capitalized even if lowercase, as with all wiki files and pages, e.g. Method and method are considered the same.

Usage

iconify(icon="Poor Laws",group="Law") gives Law poor laws.png Poor Laws

iconify(icon="University",group="Building",width="36px",text="0") gives Building university.png

iconify(icon="Morale",group="Military",mod="{{green|+10%}}") gives Military morale.png +10% Morale


local p = {};

local getArgs = require('Module:Arguments').getArgs
local uString = mw.ustring
function p.main(frame)
    local args = getArgs(frame)
    return p.iconify(args)
end

function p.iconify(args)

    local icon = uString.lower(args.icon)
    local group = args.group or ""

    icon = uString.gsub(icon, "([-'])", { ["-"] = "_", ["'"] = "" })
    --icon = uString.gsub(icon, "'", "")

    icon = args.image or uString.format("%s %s.png", group, icon)

    local width = args.width or "24px"
    local link = args.link or args.icon
    local extra = args.extra and "|" .. args.extra or ""

    local ic = uString.format("[[File:%s|link=%s|%s%s]]", icon, link, width, extra)

    if args.mod ~= nil then
        ic = uString.format("%s %s", ic, args.mod)
    end

    if args.text == "link" then
        ic = uString.format("%s [[%s|%s]]", ic, link, args.icon)
    elseif args.text == "nosp" then
        ic = ic .. args.icon -- no space, so no need for format
    elseif args.text == nil then
        ic = uString.format("%s %s", ic, args.icon)
    end

    return ic
end

return p