Module:File link

From annadreambrush.com/wiki
Revision as of 01:45, 30 May 2014 by imported>Mr. Stradivarius (beginnings of an image library)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Documentation for this module may be created at Module:File link/doc

local image = {}

function image.new()
	local obj, data = {}, {}
	
	function data:name(s)
		self.theName = s
	end
	
	function data:format(s, filename)
		local validFormats = {
			thumb = true,
			thumbnail = true,
			frame = true,
			framed = true,
			frameless = true
		}
		if validFormats[s] then
			self.theFormat = s
			self.theFormatFilename = filename
		else
			error('invalid format')
		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
	
	function data:location(s)
		local validLocations = {
			right = true,
			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
	
	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
			error(string.format(
				"bad argument #1 to 'data:alignment'"
			))
		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
	
	function data:caption(s)
		self.theCaption = s
	end
	
	function data:render()
	end
	
	return obj
end

return image