Module:Infoicon

p={}; -- the basics of the main function, function icon local data=require("Module:Infoicon/data"); local sizes=require("Module:Infoicon/sizes"); --the output format local fmt="%s  ";

-- get the default tooltip for the item. In most cases.the item will be a string with all words starting with capital letters; in these cases, we simply want to lower case all but the first word. In a small number of more complex cases, we actually need to define the tooltip separately from the image; in these cases, we use a 2-entry table to include both. local function gettooltip(itemData) if (type(itemData)=="table") then return itemData["tip"]; else local i= string.find(itemData," "); if i==nil then return itemData; else return string.sub(itemData,1,i).. string.lower(string.sub(itemData,i+1)); end end end

local function imageName(itemData) if (type(itemData)=="table") then return itemData["image"]; else retVal=itemData; repeat i=string.find(retVal, "(",1,true);			if i~=nil then				j=string.find(retVal,")",i,true); retVal=string.sub(retVal,1,i-1)..string.sub(retVal,j+1); end until i==nil; return retVal..".png"; end end

function p.icon(frame) args=frame:getParent.args; dataItem = data[string.lower(args[1])]; if (dataItem==nil) then dataItem = data[1]; end ---generate the params to place in the format ---Note that param #6 duplicates param #1 local param1,param2,param3,param4,param5,param7; param1=args["tooltip"]; if (param1==nil) then param2=gettooltip(dataItem); param3=""; param1=args["link"]; if (param1==nil) then param1=args[1]; end else param2=param1; param3=param1; end param4=imageName(dataItem); size=args[2]; if size ==nil then size=1;--default size value end if sizes[size]~=nil then param5=sizes[size]; else param5=size; end param7=args["link"]; if param7==nil then param7=""; end return string.format(fmt,param1,param2,param3,param4,param5,param1,param7); end function p.dataTable(frame) retVal= "{|Border=\"1\"\n|name||tooltip||filename\n"; keys={}; for i,j in pairs(data) do		if type(i)=="string" then table.insert(keys,i); end end table.sort(keys); for i,j in pairs(keys) do		dataItem = data[j]; retVal=retVal.."|-\n|"..j.."||"..gettooltip(dataItem).."||File:"..imageName(dataItem).."\n"; end retVal=retVal.."|-\n|(anything else)||"..gettooltip(data[1]).."||File:"..imageName(data[1]).."\n"; retVal=retVal.."|}"; return retVal; end

function p.sizeTable(frame) retVal ="{|Border=\"1\"\n|name||size value\n"; for i,j in pairs(sizes) do		if type(i)=="string" then retVal=retVal.."|-\n|"..i.."||"..j.."\n"; end end retVal=retVal.."|-\n|(unspecified)||"..sizes[1].."\n|}"; return retVal; end

return p;