Module:ResourceLink: Difference between revisions
From Against the Storm Official Wiki
(changed error message) |
(fixed a logic error preventing sizing from work--I hope) |
||
Line 12: | Line 12: | ||
function ResourceLink.renderLink(frame) | function ResourceLink.renderLink(frame) | ||
local | local strResourceName = frame.args.image | ||
local | local strIconSize = frame.args.size | ||
local strFilename = IconFilenames.getIconFilename( | local strFilename = IconFilenames.getIconFilename(strResourceName) | ||
-- if looking up the provided image name returned nil, then render an error | -- if looking up the provided image name returned nil, then render an error | ||
if not strFilename then | if not strFilename then | ||
return " | return "renderIcon Error: file " .. strResourceName .." not found" | ||
end | end | ||
Line 27: | Line 27: | ||
-- small, or in-line size. | -- small, or in-line size. | ||
local strFileSize = "{{ImgS}}" | local strFileSize = "{{ImgS}}" | ||
if "med" == | if "med" == strIconSize then | ||
strFileSize = "{{ImgM}}" | strFileSize = "{{ImgM}}" | ||
elseif "large" == | elseif "large" == strIconSize then | ||
strFileSize = "{{ImgL}}" | strFileSize = "{{ImgL}}" | ||
elseif "huge" == | elseif "huge" == strIconSize then | ||
strFileSize = "{{ImgH}}" | strFileSize = "{{ImgH}}" | ||
end | end | ||
local strFilePart = string.format("[[File:%s|%s]]", strFilename, | local strFilePart = string.format("[[File:%s|%s]]", strFilename, strFileSize) | ||
-- build the link based on the name of the resource passed in | -- build the link based on the name of the resource passed in | ||
local strLinkPart = "[[" .. | local strLinkPart = "[[" .. strResourceName .. "]]" | ||
return strFilePart .. " " .. strLinkPart | return strFilePart .. " " .. strLinkPart |
Revision as of 14:28, 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 strResourceName = frame.args.image local strIconSize = frame.args.size local strFilename = IconFilenames.getIconFilename(strResourceName) -- if looking up the provided image name returned nil, then render an error if not strFilename then return "renderIcon Error: file " .. strResourceName .." 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" == strIconSize then strFileSize = "{{ImgM}}" elseif "large" == strIconSize then strFileSize = "{{ImgL}}" elseif "huge" == strIconSize then strFileSize = "{{ImgH}}" end local strFilePart = string.format("[[File:%s|%s]]", strFilename, strFileSize) -- build the link based on the name of the resource passed in local strLinkPart = "[[" .. strResourceName .. "]]" return strFilePart .. " " .. strLinkPart end return ResourceLink