Anonymous

Module:Icons: Difference between revisions

From Melvor Idle
Icon: Minor argument parsing amends to facilitate invocation directly with {{#invoke}}
(Slight extension override name adjustment)
(Icon: Minor argument parsing amends to facilitate invocation directly with {{#invoke}})
Line 1: Line 1:
--You can't generate Templates from within Lua due to the loading order, so instead copying the Icon functionality into a module so it can be pulled elsewhere.
--You can't generate Templates from within Lua due to the loading order, so instead copying the Icon functionality into a module so it can be pulled elsewhere.
--Should function very similarly to how Template:Icon works
--Should function very similarly to how Template:Icon works
local Shared = require("Module:Shared")


local p = {}
local p = {}
Line 259: Line 261:
--Ambiguous overrides section
--Ambiguous overrides section
local ambiguousOverrides = {'Golbin', 'Chick', 'Chicken', 'Cyclops', 'Wizard'}
local ambiguousOverrides = {'Golbin', 'Chick', 'Chicken', 'Cyclops', 'Wizard'}
local Shared= require("Module:Shared")


function p.Icon(frame)
function p.Icon(frame)
Line 267: Line 267:
   local text = args[2]
   local text = args[2]
   local iconType = args.type
   local iconType = args.type
   local ext = args.ext ~= nil and args.ext or 'svg'
   local ext = args.ext ~= nil and args.ext ~= '' and args.ext or 'svg'
   local notext = args.notext ~= nil and args.notext ~= ''
   local notext = args.notext ~= nil and args.notext ~= ''
   local nolink = args.nolink ~= nil and args.nolink ~= ''
   local nolink = args.nolink ~= nil and args.nolink ~= ''
Line 274: Line 274:
   local imgSize = args.size ~= nil and args.size or 25
   local imgSize = args.size ~= nil and args.size or 25
   local qty = args.qty
   local qty = args.qty
   local img = args.img ~= nil and args.img or link
   local img = args.img ~= nil and args.img ~= '' and args.img or link


   link = Shared.fixPagename(link)
   link = Shared.fixPagename(link)
Line 291: Line 291:
end
end
   end
   end
   if text == nil and txtOverrides[link] ~= nil then
   if (text == nil or text == '') and txtOverrides[link] ~= nil then
     text = txtOverrides[link]
     text = txtOverrides[link]
   end
   end
   if linkOverrides[link] ~= nil then
   if linkOverrides[link] ~= nil then
     if text == nil then text = link end
     if (text == nil or text == '') then text = link end
     link = linkOverrides[link]
     link = linkOverrides[link]
   end
   end
Line 310: Line 310:
   --There are a couple specific double overrides I want to include that don't fit in the above lists
   --There are a couple specific double overrides I want to include that don't fit in the above lists
   if Shared.contains(ambiguousOverrides, link) then
   if Shared.contains(ambiguousOverrides, link) then
     if text == nil then text = link end
     if (text == nil or text == '') then text = link end
     link = link..' ('..(iconType == 'mark' and 'item' or iconType)..')'
     link = link..' ('..(iconType == 'mark' and 'item' or iconType)..')'
   end
   end