Jump to content

Module:File link: Difference between revisions

929 bytes added ,  10 years ago
add start, end, and thumbtime
(don't include the library name in checkSelf method names)
(add start, end, and thumbtime)
Line 184: Line 184:
checkType('fileLink:lang', 1, s, 'string', true)
checkType('fileLink:lang', 1, s, 'string', true)
data.theLang = s
data.theLang = s
return self
end
local function checkTypeStringOrNum(funcName, pos, arg)
local argType = type(arg)
if argType ~= 'nil' and argType ~= 'string' and argType ~= 'number' then
error(string.format(
"bad argument #%d to '%s' (string or number expected, got %s)",
pos,
funcName,
argType
), 3)
end
end
function data:startTime(time)
checkSelf(self, 'startTime')
checkTypeStringOrNum('fileLink:startTime', 1, time)
data.theStartTime = time
return self
end
function data:endTime(time)
checkSelf(self, 'endTime')
checkTypeStringOrNum('fileLink:endTime', 1, time)
data.theEndTime = time
return self
end
function data:thumbTime(time)
checkSelf(self, 'thumbTime')
checkTypeStringOrNum('fileLink:thumbTime', 1, time)
data.theThumbTime = time
return self
return self
end
end
Line 236: Line 269:
-- Render named parameters.
-- Render named parameters.
-- That includes link, alt, page, class, and lang.
-- That includes link, alt, page, class, lang, start, end, and thumbtime.
do
do
local namedParameters = {'link', 'alt', 'page', 'class', 'lang'}
local namedParameters = {
for i, parameter in ipairs(namedParameters) do
{'link', 'theLink'},
local dataField = 'the' .. parameter:sub(1, 1):upper() .. parameter:sub(2, -1)
{'alt', 'theAlt'},
local value = data[dataField]
{'page', 'thePage'},
{'class', 'theClass'},
{'lang', 'theLang'},
{'start', 'theStartTime'},
{'end', 'theEndTime'},
{'thumbtime', 'theThumbTime'}
}
for i, t in ipairs(namedParameters) do
local parameter = t[1]
local value = data[t[2]]
if value then
if value then
ret[#ret + 1] = parameter .. '=' .. tostring(value)
ret[#ret + 1] = parameter .. '=' .. tostring(value)
Cookies help us deliver our services. By using our services, you agree to our use of cookies.