Module:File link: Difference between revisions
Content added Content deleted
Enwikipedia>Mr. Stradivarius (allow specifying height and width values as strings ending in px) |
Enwikipedia>Mr. Stradivarius m (Undid revision 611451330 by Mr. Stradivarius (talk) whoops, that edit was supposed to be to the sandbox...) |
||
Line 5: | Line 5: | ||
local fileLink = {} |
local fileLink = {} |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
function fileLink.new(filename) |
function fileLink.new(filename) |
||
Line 64: | Line 52: | ||
end |
end |
||
local function |
local function sizeError(methodName) |
||
-- |
-- Used for formatting duplication errors in size-related methods. |
||
⚫ | |||
-- using checkTypeStringOrNum, so will be a string, a number, or nil. |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
methodName |
|||
⚫ | |||
⚫ | |||
⚫ | |||
method |
|||
⚫ | |||
⚫ | |||
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 |
|||
-- 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 |
end |
||
function data:width(px) |
function data:width(px) |
||
checkSelf(self, 'width') |
checkSelf(self, 'width') |
||
checkType('fileLink:width', 1, px, 'number', true) |
|||
⚫ | |||
sizeError('fileLink:width') |
|||
⚫ | |||
data.theWidth = px |
data.theWidth = px |
||
return self |
return self |
||
Line 107: | Line 73: | ||
function data:height(px) |
function data:height(px) |
||
checkSelf(self, 'height') |
checkSelf(self, 'height') |
||
checkType('fileLink:height', 1, px, 'number', true) |
|||
if px and data.isUpright then |
|||
sizeError('fileLink:height') |
|||
⚫ | |||
data.theHeight = px |
data.theHeight = px |
||
return self |
return self |
||
Line 217: | Line 185: | ||
data.theLang = s |
data.theLang = s |
||
return self |
return self |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end |
end |
||