Jump to content

Module:File link: Difference between revisions

691 bytes added ,  10 years ago
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
-- Link
-- Render named parameters.
if data.theLink then
-- That includes link, alt, page, class, and lang.
ret[#ret + 1] = 'link=' .. data.theLink
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
 
-- Alt
if data.theAlt then
ret[#ret + 1] = 'alt=' .. data.theAlt
end
-- Caption
-- Caption
ret[#ret + 1] = data.theCaption
ret[#ret + 1] = data.theCaption
Cookies help us deliver our services. By using our services, you agree to our use of cookies.