Module:PerkLink

--- -- Renders the template -- -- Takes an argument, the name of the perk. Optionally, accepts a second -- argument, "med" or "large" to render the icon as larger than the standard -- size of text, ---

local PerkLink = {}

local PerkData = require("Module:PerkData") -- lookup table for perks

--- -- Constants --- local TEMPLATE_IMGSMALL = "ImgS" local TEMPLATE_IMGMED = "ImgM" local TEMPLATE_IMGLARGE = "ImgL" local TEMPLATE_IMGHUGE = "ImgH"

local REPLACEMENT_FILENAME = "Question_mark.png"

--- -- Main rendering function -- uses PerkData lookup function, parses the result and handles errors -- with default values, then assembles a final string to return to the wiki --- function PerkLink.renderLink(frame) local argPerkName = frame.args.perk local argPerkIconSize = frame.args.iconsize if not argPerkName then return "Perk_Link Error: no perk given" end -- get the data about the perk and then adopt the provided name -- in case we need to look it up again local tableData = PerkData.getData(argPerkName) if not tableData then return "Resource_Link Error: " .. argPerkName .." not found" end local strPageName = PerkData.getPagenameFromData(tableData) -- if looking up the provided perk name returned no page, then render an error if not strPageName then return "Resource_Link Error: " .. argPerkName .." not found" end -- if the icon filename didn't exist, then show a default but subtle question mark icon instead -- this will help people with troubleshooting, instead of just showing no icon then editors -- wonder what went wrong local strIconFilename = PerkData.getIconFilenameFromData(tableData) or REPLACEMENT_FILENAME -- use the established templates for image sizes, with the default being -- small, or in-line size, for perks local switchIconSize = { ["med"] = frame:expandTemplate{title=TEMPLATE_IMGMED}, ["large"] = frame:expandTemplate{title=TEMPLATE_IMGLARGE}, ["huge"] = frame:expandTemplate{title=TEMPLATE_IMGHUGE} }	-- if it's not in the switch, then use the default, small size local strIconSize = switchIconSize[argPerkIconSize] or frame:expandTemplate{title=TEMPLATE_IMGSMALL} -- combine the string parts to return to the page local strFilePart = string.format("", strIconFilename, strIconSize, strPageName, strPageName, strPageName) -- combine the file part with the link part return strFilePart .. " " .. strPageName .. "" end

--- -- Return when required into another Module. --- return PerkLink