Module:ResourceLink: Difference between revisions
From Against the Storm Official Wiki
No edit summary |
forcing transclusion might work? |
||
| Line 26: | Line 26: | ||
-- use the established templates for image sizes, with the default being | -- use the established templates for image sizes, with the default being | ||
-- small, or in-line size. | -- small, or in-line size. | ||
local strFileSize = " | local strFileSize = frame:expandTemplate{title="ImgS"} | ||
if "med" == strIconSize then | if "med" == strIconSize then | ||
strFileSize = " | strFileSize = frame:expandTemplate{title="ImgM"} | ||
elseif "large" == strIconSize then | elseif "large" == strIconSize then | ||
strFileSize = " | strFileSize = frame:expandTemplate{title="ImgL"} | ||
elseif "huge" == strIconSize then | elseif "huge" == strIconSize then | ||
strFileSize = " | strFileSize = frame:expandTemplate{title="ImgH"} | ||
end | end | ||
local strFilePart = string.format("[[File:%s|%s]]", strFilename, strFileSize) | local strFilePart = string.format("[[File:%s|%s]]", strFilename, strFileSize) | ||
Revision as of 15:18, 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 = frame:expandTemplate{title="ImgS"}
if "med" == strIconSize then
strFileSize = frame:expandTemplate{title="ImgM"}
elseif "large" == strIconSize then
strFileSize = frame:expandTemplate{title="ImgL"}
elseif "huge" == strIconSize then
strFileSize = frame:expandTemplate{title="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


