Module:Li

From Story Lists
Revision as of 14:23, 24 March 2022 by DanielCM (talk | contribs)
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 = 'x230px'
		noimage_css = 'li-noimage-block'
	end

	args = frame:getParent().args

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

	for i=1, max_images do
		if args['noimage'] ~= nil then
			result = result .. image ( nil, nil, args['noimage'] )
		elseif i == 1 and args['image'] == nil then
			result = result .. image ( nil, nil, 'Image not found' )
		elseif args['image' .. i] == nil then
			break
		else
			result = result .. image ( args['image' .. i], args['imagedesc' .. i], args['noimage' .. i] )
		end
	end

	for i=1, max_lines do
		if args[i] == nil then
			break
		elseif args[i-1] == '' then
			result = result .. '<div class="li-text"><br>' .. args[i] .. '</div>'
		else
			result = result .. '<div class="li-text">' .. args[i] .. '</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