Module:File link: Difference between revisions
add page, class and lang parameters
(allow nil values as input to most of the functions, to make call-chaining with conditional variables easier) |
(add page, class and lang parameters) |
||
Line 163: | Line 163: | ||
checkType('image:alt', 1, s, 'string', true) | checkType('image:alt', 1, s, 'string', true) | ||
data.theAlt = s | data.theAlt = s | ||
return self | |||
end | |||
function data:page(num) | |||
checkSelf(self, 'image:page') | |||
checkType('image:page', 1, num, 'number', true) | |||
data.thePage = s | |||
return self | |||
end | |||
function data:class(s) | |||
checkSelf(self, 'image:class') | |||
checkType('image:class', 1, s, 'string', true) | |||
data.theClass = s | |||
return self | |||
end | |||
function data:lang(s) | |||
checkSelf(self, 'image:lang') | |||
checkType('image:lang', 1, s, 'string', true) | |||
data.theLang = s | |||
return self | return self | ||
end | end | ||
Line 214: | Line 235: | ||
end | end | ||
-- | -- Render named parameters. | ||
if | -- That includes link, alt, page, class, and lang. | ||
do | |||
local namedParameters = {'link', 'alt', 'page', 'class', 'lang'} | |||
for i, parameter in ipairs(namedParameters) do | |||
local dataField = 'the' .. parameter:sub(1, 1):upper() .. parameter:sub(2, -1) | |||
local value = data[dataField] | |||
if value then | |||
ret[#ret + 1] = parameter .. '=' .. tostring(value) | |||
end | |||
end | |||
end | end | ||
-- Caption | -- Caption | ||
ret[#ret + 1] = data.theCaption | ret[#ret + 1] = data.theCaption |