模組:Flag/sandbox

维基百科,自由的百科全书
文档图示 模块文档[查看] [编辑] [历史] [清除缓存]

Lua-native alternative to popular flag templates. Can be used to reduce post-expand include size of pages with lots of templates, since it avoids calling multilevel templates.

Usage

Examples

Template Module
Code Output TL Code Output TL
{{flag|China}}  中國 443b {{#invoke:flag|main|China}}  China 128b
{{flagcountry|China}}  中國 577b {{#invoke:flag|country|China}}  中国 128b
{{flagdeco|China}} 452b {{#invoke:flag|deco|China}} 107b
{{flagicon|China}} 中国 548b {{#invoke:flag|icon|China}} 中国 117b
{{flag+link|History of|China}}  中国 663b {{#invoke:flag|+link|History of|China}}  China 139b
local p = {}
local yesno = require('Module:Yesno')
local mError = require('Module:Error')
local mCountryData = require('Module:CountryData')

local gFrame = mw.getCurrentFrame()

local function renderError(msg)
	return mError.error{"[[Module:Flag]]錯誤:" .. msg}
end

function p._country_data_callback(args, options)
	local file
	
	if options.checkVarient then
		file =
			args.variant and args["flag alias-" .. args.variant] or
			args.altvar and args["flag alias-" .. args.altvar] or
			args["flag alias"]
	else
		file = args["flag alias"]
	end
	if not file then
		return renderError("參數 <code>flag alias</code> 為空。")
	end
	local success, file = pcall(mw.title.new, file, 'Media')
	if not success or not file then
		return renderError("flag alias <code>" .. file .. "</code> 無效。")
	elseif not file.exists then
		return renderError("檔案 [[" .. file .. "]] 不存在。")
	end
end

return p