Anonymous user
Module:File link: Difference between revisions
allow specifying height and width values as strings ending in px
Enwikipedia>Mr. Stradivarius m (Protected Module:File link: High-risk Lua module ([Edit=Allow only template editors and admins] (indefinite) [Move=Allow only template editors and admins] (indefinite))) |
Enwikipedia>Mr. Stradivarius (allow specifying height and width values as strings ending in px) |
||
Line 5:
local fileLink = {}
error(string.format(▼
), 3)▼
end▼
function fileLink.new(filename)
Line 52 ⟶ 64:
end
local function
--
-- using checkTypeStringOrNum, so will be a string, a number, or nil.
▲ error(string.format(
if px and data.isUpright then▼
"duplicate size argument detected in '%s'"▼
error(string.format(▼
.. " ('upright' cannot be used in conjunction with height or width)",▼
▲ "duplicate size argument detected in '%s' ('upright' cannot be"
▲ ), 3)
method
), 3)▼
end▼
if type(px) == 'string' then
local origPx = px
px = px:match('^(%d+)px$') or px
px = tonumber(px)
if not px then
error(string.format(
"invalid string '%s' passed to '%s'",
origPx,
method
), 3)
end▼
end
-- px is now a number or nil.
if px and px < 1 or math.floor(px) ~= px then
error(string.format(
"invalid image size specified in '%s' (size must be a positive"
.. 'integer)',
method
), 3)
end
return px
end
function data:width(px)
checkSelf(self, 'width')
▲ if px and data.isUpright then
▲ sizeError('fileLink:width')
▲ end
data.theWidth = px
return self
Line 73 ⟶ 107:
function data:height(px)
checkSelf(self, 'height')
▲ sizeError('fileLink:height')
▲ end
data.theHeight = px
return self
Line 185 ⟶ 217:
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
|