Database changes have finished applying - please report any issues you're (still) seeing to support@shoutwiki.com.

Module:Toolbar

From TechInfoDepot
Jump to navigationJump to search
Documentation icon Module documentation[view] [edit] [history] [purge]

This module implements {{toolbar}}. Please see the template page for documentation.

 1 -- This module implements {{toolbar}}.
 2 
 3 local mArguments -- Lazily initialise [[Module:Arguments]]
 4 local mTableTools = require('Module:TableTools')
 5 local yesno = require('Module:Yesno')
 6 
 7 local p = {}
 8 
 9 function p.main(frame)
10 	mArguments = require('Module:Arguments')
11 	local args = mArguments.getArgs(frame)
12 	return p._main(args)
13 end
14 
15 function p._main(args)
16 	local toolbarItems = p.makeToolbarItems(args)
17 	if not toolbarItems then
18 		-- Return the blank string if no arguments were specified, rather than
19 		-- returning empty brackets.
20 		return ''
21 	elseif yesno(args.span) == false then
22 		return string.format(
23 			'(%s)',
24 			toolbarItems
25 		)
26 	else
27 		return string.format(
28 			'<span class="plainlinks%s"%s>(%s)</span>',
29 			type(args.class) == 'string' and ' ' .. args.class or '',
30 			type(args.style) == 'string' and string.format(' style="%s"', args.style) or '',
31 			toolbarItems
32 		)
33 	end
34 end
35 
36 function p.makeToolbarItems(args)
37 	local nums = mTableTools.numKeys(args)
38 	local sep = (args.separator or 'pipe') .. '-separator'
39 	sep = mw.message.new(sep):plain()
40 	local ret = {}
41 	for i, v in ipairs(nums) do
42 		ret[#ret + 1] = mw.ustring.gsub(args[v], "%[%[::+(.-)%]%]", "[[:%1]]")
43 	end
44 	if #ret > 0 then
45 		return table.concat(ret, sep)
46 	else
47 		return nil
48 	end
49 end
50 
51 return p