Difference between revisions of "Module:Flag/sandbox"

From blackwiki
Jump to navigation Jump to search
blackwiki>Ahecht
(flagdeco)
blackwiki>Ahecht
(refactor code, add {{flag}})
Line 1: Line 1:
 
local p = {}
 
local p = {}
  
function p.icon(frame)
+
function p._main(frame, name, mode, check)
 
local args={}
 
local args={}
 
 
Line 15: Line 15:
 
end
 
end
 
 
local opts = {
+
if check then
unknown='{{main other|[[Category:Pages using flagicon template with unknown parameters|_VALUE_' .. frame:getParent():getTitle() .. ']]}}',
+
local opts = {
preview='Page using [[Template:Flagicon]] with unknown parameter "_VALUE_"',
+
unknown='{{main other|[[Category:Pages using ' .. mw.ustring.lower(name) .. ' template with unknown parameters|_VALUE_' .. frame:getParent():getTitle() .. ']]}}',
 +
preview='Page using [[Template:' .. name .. ']] with unknown parameter "_VALUE_"',
 
ignoreblank='y',
 
ignoreblank='y',
 
[1] = '1',
 
[1] = '1',
Line 26: Line 27:
 
}
 
}
 
 
local check = require('Module:Check for unknown parameters')._check(opts,args)
+
check = require('Module:Check for unknown parameters')._check(opts,args)
 +
else
 +
check = ''
 +
end
 
 
 
args['variant'] = args[2] or args['variant']
 
args['variant'] = args[2] or args['variant']
 
args[2] = args[1]
 
args[2] = args[1]
args[1] = 'cxxlo'
+
args[1] = mode
args['missingcategory'] = '[[Category:Flagicons with missing country data templates]]'
+
args['missingcategory'] = '[[Category:' .. name .. 'with missing country data templates]]'
 
args['noredlink'] = args['noredlink'] or 'no'
 
args['noredlink'] = args['noredlink'] or 'no'
 +
 +
if require('Module:Yesno')(args['placeholder']) ~= true then
 +
args[1] = args[1] .. 'o'
 +
end
 
 
 
return require('Module:Flagg/sandbox').luaMain(frame,args)..check
 
return require('Module:Flagg/sandbox').luaMain(frame,args)..check
 
end
 
end
  
function p.deco(frame)
+
function p.main(frame) return p._main(frame, 'Flag',    'unc',  false) end
local args={}
+
function p.deco(frame) return p._main(frame, 'Flagdeco', 'uxx',  false) end
+
function p.icon(frame) return p._main(frame, 'Flagicon', 'cxxl', true ) end
for k,v in pairs(frame:getParent().args) do
 
if (v or '') ~= '' then
 
args[k] = v
 
end
 
end
 
for k,v in pairs(frame.args) do
 
if (v or '') ~= '' then
 
args[k] = v
 
end
 
end
 
 
args['variant'] = args[2] or args['variant']
 
args[2] = args[1]
 
args[1] = 'uxxo'
 
args['missingcategory'] = '[[Category:Flagdeco with missing country data templates]]'
 
args['noredlink'] = args['noredlink'] or 'no'
 
 
return require('Module:Flagg/sandbox').luaMain(frame,args)
 
end
 
  
 
return p
 
return p

Revision as of 19:43, 6 May 2020

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

local p = {}

function p._main(frame, name, mode, check)
	local args={}
	
	for k,v in pairs(frame:getParent().args) do
		if (v or '') ~= '' then
			args[k] = v
		end
	end
	for k,v in pairs(frame.args) do
		if (v or '') ~= '' then
			args[k] = v
		end
	end
	
	if check then
		local opts = {
		unknown='{{main other|[[Category:Pages using ' .. mw.ustring.lower(name) .. ' template with unknown parameters|_VALUE_' .. frame:getParent():getTitle() .. ']]}}',
		preview='Page using [[Template:' .. name .. ']] with unknown parameter "_VALUE_"',
		ignoreblank='y',
		[1] = '1',
		[2] = '2',
		[3] = 'noredlink',
		[4] = 'size',
		[5] = 'variant'
		}
	
		check = require('Module:Check for unknown parameters')._check(opts,args)
	else
		check = ''
	end
	
	args['variant'] = args[2] or args['variant']
	args[2] = args[1]
	args[1] = mode
	args['missingcategory'] = '[[Category:' .. name .. 'with missing country data templates]]'
	args['noredlink'] = args['noredlink'] or 'no'
	
	if require('Module:Yesno')(args['placeholder']) ~= true then
		args[1] = args[1] .. 'o'
	end
	
	return require('Module:Flagg/sandbox').luaMain(frame,args)..check
end

function p.main(frame) return p._main(frame, 'Flag',     'unc',  false) end
function p.deco(frame) return p._main(frame, 'Flagdeco', 'uxx',  false) end
function p.icon(frame) return p._main(frame, 'Flagicon', 'cxxl', true ) end

return p