Editing Module:File link
From MINR.ORG WIKI
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
− | + | local image = {} | |
− | + | function image.new() | |
− | local | + | local obj, data = {}, {} |
− | + | ||
− | + | function data:name(s) | |
− | + | self.theName = s | |
− | function | + | end |
− | + | ||
− | + | function data:format(s, filename) | |
− | + | local validFormats = { | |
− | + | thumb = true, | |
− | + | thumbnail = true, | |
− | if | + | frame = true, |
− | + | framed = true, | |
− | + | frameless = true | |
− | + | } | |
− | + | if validFormats[s] then | |
+ | self.theFormat = s | ||
+ | self.theFormatFilename = filename | ||
+ | else | ||
+ | error('invalid format') | ||
end | end | ||
end | end | ||
− | + | ||
− | + | function data:width(px) | |
− | + | self.theWidth = px | |
− | + | end | |
− | + | ||
− | + | function data:height(px) | |
− | + | self.theHeight = px | |
− | + | end | |
+ | |||
+ | function data:upright(factor) | ||
+ | self.isUpright = true | ||
+ | self.uprightFactor = factor | ||
+ | end | ||
+ | |||
+ | function data:resetSize() | ||
+ | for i, field in ipairs{'theWidth', 'theHeight', 'isUpright', 'uprightFactor'} do | ||
+ | self[field] = nil | ||
end | end | ||
− | |||
− | |||
end | end | ||
− | + | ||
− | + | function data:location(s) | |
− | + | local validLocations = { | |
− | + | right = true, | |
− | local | + | left = true, |
− | + | center = true, | |
− | + | none = true | |
+ | } | ||
+ | if s and validLocations[s] then | ||
+ | self.theLocation = s | ||
+ | else | ||
+ | error(string.format( | ||
+ | "bad argument #1 to 'image:location'" | ||
+ | .. " (must be one of 'right', 'left', 'center' or 'none'; got '%s').", | ||
+ | tostring(s) | ||
+ | )) | ||
end | end | ||
− | |||
− | |||
end | end | ||
− | + | ||
− | + | function data:alignment(s) | |
− | + | local validAlignments = { | |
− | + | baseline = true, | |
− | + | middle = true, | |
− | + | sub = true, | |
− | + | super = true, | |
− | + | ['text-top'] = true, | |
− | + | ['text-bottom'] = true, | |
− | + | top = true, | |
− | + | bottom = true | |
+ | } | ||
+ | if s and validAlignments[s] then | ||
+ | self.theAlignment = s | ||
else | else | ||
− | + | error(string.format( | |
+ | "bad argument #1 to 'data:alignment'" | ||
+ | )) | ||
end | end | ||
end | end | ||
− | + | ||
− | + | function data:border() | |
− | + | self.hasBorder = true | |
− | + | end | |
+ | |||
+ | function data:link(s) | ||
+ | self.theLink = s | ||
+ | end | ||
+ | |||
+ | function data:alt(s) | ||
+ | self.theAlt = s | ||
end | end | ||
− | + | ||
− | + | function data:caption(s) | |
− | + | self.theCaption = s | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
− | + | ||
− | + | function data:render() | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
− | return | + | |
+ | return obj | ||
end | end | ||
− | return | + | return image |