模块:Flag/sandbox
外观
![]() | 这是Module:Flag(差异)的沙盒。 |
![]() | 此模块沙盒已评为beta版,可广泛使用。因其新近完成,请谨慎使用,以确保输出结果符合预期。 |
![]() | 此模块使用Lua语言: |
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
[编辑]- {{flag}} → {{#invoke:flag|main}}
- {{flagcountry}} → {{#invoke:flag|country}}
- {{flagdeco}} → {{#invoke:flag|deco}}
- {{flagicon}} → {{#invoke:flag|icon}}
- {{flag+link}} → {{#invoke:flag|+link}}
Examples
[编辑]Template | Module | ||||
---|---|---|---|---|---|
Code | Output | TL | Code | Output | TL |
{{flag|China}} |
![]() |
443b | {{#invoke:flag|main|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}} |
![]() |
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