Difference between revisions of "Module:Portal image banner/sandbox"

From blackwiki
Jump to navigation Jump to search
test>FR30799386
(Create sandbox version of Module:Portal image banner....will do rest tmrw)
 
test>FR30799386
(testing)
Line 30: Line 30:
 
end
 
end
 
local lines=makeGalleryLinesTable(args)
 
local lines=makeGalleryLinesTable(args)
return makeOutput(lines, args.overflow, args.maxheight)
+
return makeOutput(lines, args.overflow, args.maxheight, args.mode)
 
end
 
end
  
Line 39: Line 39:
 
end
 
end
  
function makeGalleryLine(file, caption, link)
+
function makeGalleryLineSlideshow(file, caption)
 
local title = mw.title.new(file, "File" )
 
local title = mw.title.new(file, "File" )
local linktext = ( link and '{{!}}link=' .. link  or '' )
+
return title.prefixedText .. '{{!}}' .. ( caption or '' )  
return title.prefixedText .. '{{!}}' .. ( caption or '' )
 
 
end
 
end
 +
  
 
function makeGalleryLinesTable(args)
 
function makeGalleryLinesTable(args)
Line 50: Line 50:
 
while args[i] do
 
while args[i] do
 
if args.mode==nil then  
 
if args.mode==nil then  
table.insert(galleryLinesTable, makeGalleryLine(args[i], args[i+1],args.link))
+
table.insert(galleryLinesTable, makeGalleryLine(args[i], args[i+1],args.link))
 
else if args.mode=='slideshow' then
 
else if args.mode=='slideshow' then
table.insert(galleryLinesTable, makeGalleryLineSlideshow(args[i], args[i+1], args.link))
+
table.insert(galleryLinesTable, makeGalleryLineSlideshow(args[i], args[i+1], args.link))  
 
else  
 
else  
 
error('Mode not supported')
 
error('Mode not supported')
end
+
end
 
i = i + 2
 
i = i + 2
 
end
 
end
 
return galleryLinesTable  
 
return galleryLinesTable  
 
end
 
end
function makeOutput(imageLines,overflow,maxHeight)
+
function makeOutput(imageLines,overflow,maxHeight,mode)
 
local randomiseArgs = { ['t'] = imageLines }
 
local randomiseArgs = { ['t'] = imageLines }
 
local randomisedLines = randomModule.main('array', randomiseArgs )
 
local randomisedLines = randomModule.main('array', randomiseArgs )
 
local galleryContent = table.concat(randomisedLines, '\n',1,1)  
 
local galleryContent = table.concat(randomisedLines, '\n',1,1)  
 
local output
 
local output
if mode==nil then
+
if not mode then
output = '<div class="portal-banner-image" style="max-height:' .. (maxHeight or 'intial') .. '; overflow:'..(overflow or 'auto')..';">'..galleryContent..'</div>'
+
output = '<div class="portal-banner-image" style="max-height:' .. (maxHeight or 'intial') .. '; overflow:'..(overflow or 'auto')..';">'..galleryContent..'</div>'
 
else if mode=='slideshow' then
 
else if mode=='slideshow' then
output='<div class="portal-banner-image-slideshow" style="max-height:' .. (maxHeight or 'intial') .. '; overflow:'..(overflow or 'auto')..';">'..'{{#tag:gallery|'..galleryContent..'|mode=slideshow}}'..'</div>'
+
output='<div class="portal-banner-image-slideshow" style="max-height:' .. (maxHeight or 'intial') .. '; overflow:'..(overflow or 'auto')..';">'..'{{#tag:gallery|'..galleryContent..'|mode=slideshow}}'..'</div>'
 +
else
 +
error('Mode not supported')
 
end
 
end
 +
 +
return output
 
end
 
end
end
+
end
return output
+
end
end
 
 
 
 
return p
 
return p

Revision as of 10:40, 10 September 2018

Documentation for this module may be created at Module:Portal image banner/sandbox/doc

local p = {}
local randomModule = require('Module:Random')

p.main = function(frame)
	local parent = frame.getParent(frame)
	local parentArgs = parent.args
	local args = cleanupArgs(parentArgs)
	local output = p._main(args)
	return frame:preprocess(output)
end

function cleanupArgs(argsTable)
	local cleanArgs = {}
	for key, val in pairs(argsTable) do
		if type(val) == 'string' then
			val = val:match('^%s*(.-)%s*$')
			if val ~= '' then
				cleanArgs[key] = val
			end
		else
			cleanArgs[key] = val
		end
	end
	return cleanArgs
end

p._main = function(args)
	if not args[1] then
		return error(linked and 'No page specified' or 'No page specified', 0)
	end
	local lines=makeGalleryLinesTable(args)
	return makeOutput(lines, args.overflow, args.maxheight, args.mode)
end

function makeGalleryLine(file, caption, link)
	local title = mw.title.new(file, "File" )
	local linktext = ( link and '{{!}}link=' .. link  or '' )
	return '[[' .. title.prefixedText ..(caption and'{{!}}'..caption or '').. linktext ..']]' .. (caption and '<div style="text-align:center;">' .. caption ..'</div>' or '') 
end

function makeGalleryLineSlideshow(file, caption)
	local title = mw.title.new(file, "File" )
	return title.prefixedText .. '{{!}}' .. ( caption or '' ) 
end


function makeGalleryLinesTable(args)
	local galleryLinesTable = {}
	local i = 1
	while args[i] do
		if args.mode==nil then 
			table.insert(galleryLinesTable, makeGalleryLine(args[i], args[i+1],args.link))
		else if args.mode=='slideshow' then
			table.insert(galleryLinesTable, makeGalleryLineSlideshow(args[i], args[i+1], args.link)) 
		else 
			error('Mode not supported')
	end
		i = i + 2
	end
	return galleryLinesTable 
end
function makeOutput(imageLines,overflow,maxHeight,mode)
	local randomiseArgs = {	['t'] = imageLines }
	local randomisedLines = randomModule.main('array', randomiseArgs )
	local galleryContent = table.concat(randomisedLines, '\n',1,1) 
	local output
	if not mode then
		output = '<div class="portal-banner-image" style="max-height:' .. (maxHeight or 'intial') .. '; overflow:'..(overflow or 'auto')..';">'..galleryContent..'</div>'
	else if mode=='slideshow' then
		output='<div class="portal-banner-image-slideshow" style="max-height:' .. (maxHeight or 'intial') .. '; overflow:'..(overflow or 'auto')..';">'..'{{#tag:gallery|'..galleryContent..'|mode=slideshow}}'..'</div>'
	else
		error('Mode not supported')
	end
	
		return output
	end
end
end
return p