Jump to content

Module:Excerpt slideshow/sandbox

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Evad37 (talk | contribs) at 03:32, 21 July 2018 (Create sandbox version of Module:Excerpt slideshow). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) โ† Previous revision | Latest revision (diff) | Newer revision โ†’ (diff)
local p = {}
local excerptModule =  require('Module:Excerpt')
local slideshowModule = require('Module:Random slideshow')

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

local makeGalleryArgs = function(titles, options)
	local galleryArgs = {}
	local i = 1
	while titles[i] do
		local excerpt = excerptModule.main({titles[i]}, options)
		if excerpt then
			local text = '<div style{{=}}text-align:left;>' .. mw.ustring.gsub(excerpt, '%c', '<br>') .. '</div>'
			table.insert(galleryArgs, 'File:Blank.png')
			table.insert(galleryArgs, text)
		end
		i = i + 1
	end
	return galleryArgs
end

-- randomExcerpt: Titles specified in template parameters (equivalent to {{Transclude random excerpt}})

p.randomExcerpt = function(frame)
	local parent = frame.getParent(frame)
	local output = p._randomExcerpt(parent.args)
	return frame:preprocess(output)
end

p._randomExcerpt = function(_args)
	local args = cleanupArgs(_args)
	-- check for blank value in more parameter
	if _args.more and not args.more then
		args.more = "Read more..." -- default text for blank more=
	end
	local galleryArgs = {}
	local options = args -- pick up miscellaneous options: more, errors, fileargs
	options.paraflags = excerptModule.numberflags(args.paragraphs or "") -- parse paragraphs, e.g. "1,3-5" โ†’ {"1","3-5"}
	options.fileflags = excerptModule.numberflags(args.files or "") -- parse file numbers
	local galleryArgs = makeGalleryArgs(args, options)
	return slideshowModule._main(galleryArgs, false, 'excerptSlideshow-container')
end

-- TODO  linkedExcerpt: Titles from links on a page (equivalent to {{Transclude linked excerpt}})
-- TODO  listItemExcerpt: Titles from linked list items on a page (equivalent to {{Transclude list item excerpt}})

return p