Module:Li

From Story Lists
Jump to navigation Jump to search

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

local p = {}

function p.li(frame)
	max_images = 10
	max_lines = 30

	if (frame:getParent().args['blocksize'] == 'small') then
		image_css = 'li-small-image-block'
		image_size = 'x90px'
		noimage_css = 'li-small-noimage-block'
	else
		image_css = 'li-image-block'
		image_size = 'x130px'
		noimage_css = 'li-noimage-block'
	end

	args = frame:getParent().args

	result = '<div class="li-block">'

	-- Display one or more images
	-- max_images = maximum number of images allowed
	for i=1, max_images do

		-- First image
		if i == 1 then

			-- Custom text in place of image, if any
			if args['noimage'] ~= nil then
				result = result .. image ( nil, nil, args['noimage'] )

			-- The image is displayed
			elseif args['image'] ~= nil then
				result = result .. image ( args['image'], args['imagedesc'], nil )

			-- The default 'Image not found' text is displayed
			else
				result = result .. image ( nil, nil, 'Image not found' )
			end

		-- Break the loop when an image (other than the 1st) is not found
		elseif args['image' .. i] == nil then
			break

		-- Display each image (if any), from the 2nd image onwards
		-- Parameters image2, image3, image4, and so on
		else
			result = result .. image ( args['image' .. i], args['imagedesc' .. i], args['noimage' .. i] )
		end
	end

	-- Lines of text (each unnamed argument is a line of text)
	for li=1, max_lines do

		-- Break the loop if a text argument is not found
		if args[li] == nil then
			break

		-- Add a line just with <br> if an empty text argument is found
		-- This is an empty line
		elseif args[li-1] == '' then
			result = result .. '<div class="li-text"><br>' .. args[li] .. '</div>'

		-- Displaying a line of text
		else
			result = result .. '<div class="li-text">' .. args[li] .. '</div>'
		end
	end

	result = result .. '</div>'

	return result
end

function image(image, img_description, noimage)
	if (noimage ~= nil) then

		img_result = '<div class="' .. noimage_css .. '">'

		img_result = img_result .. '<span class="li-image-space"></span>'

		img_result = img_result .. '<div class="li-noimage-text">'
		img_result = img_result .. noimage
		img_result = img_result .. '</div></div>'

	else
		img_result = '<div class="'.. image_css .. '"><div class="li-image">'

		img_result = img_result .. '<span class="li-image-space"></span>'

		img_result = img_result .. '[[File:' .. image .. '|' .. image_size .. ']]'
	
		if img_description ~= nil then
			img_result = img_result .. '<div class="li-image-text">' .. img_description .. '</div>'
		end

		img_result = img_result .. '</div></div>'
	end

	return img_result
end

return p