Module:ResourceLink: Difference between revisions
From Against the Storm Official Wiki
m (fixed local variable p to the filename and changed the main function name to be different) |
m (forgot a space in the rendered output) |
||
Line 39: | Line 39: | ||
local strLinkPart = "[[" .. strImageName .. "]]" | local strLinkPart = "[[" .. strImageName .. "]]" | ||
return strFilePart .. strLinkPart | return strFilePart .. " " .. strLinkPart | ||
end | end | ||
return ResourceLink | return ResourceLink |
Revision as of 05:06, 2 February 2023
Documentation for this module may be created at Module:ResourceLink/doc
------------------------------------------------------------------------------- -- Renders the {{resourceLink}} template -- -- Takes an argument, the name of the resource. Optionally, accepts a second -- argument, "med" or "large" to render the icon as larger than the standard -- size of text, {{ImgS}} ------------------------------------------------------------------------------- local ResourceLink = {} local IconFilenames = require("Module:IconFilenames") -- lookup table for image filenames function ResourceLink.renderLink(frame) local strImageName = frame.args.image local strImageSize = frame.args.size local strFilename = IconFilenames.getIconFilename(strImageName) -- if looking up the provided image name returned nil, then render an error if not strFilename then return "renderIcon Error: file " .. strImageName .." not found" end -- render the string to return, starting with the file tag, then the link tag -- use the established templates for image sizes, with the default being -- small, or in-line size. local strFileSize = "{{ImgS}}" if "med" == strImageSize then strFileSize = "{{ImgM}}" elseif "large" == strImageSize then strFileSize = "{{ImgL}}" elseif "huge" == strImageSize then strFileSize = "{{ImgH}}" end local strFilePart = string.format("[[File:%s|%s]]", strFilename, strImageSize) -- build the link based on the name of the resource passed in local strLinkPart = "[[" .. strImageName .. "]]" return strFilePart .. " " .. strLinkPart end return ResourceLink