模組:Lua banner
觀
今本(此為底本,未經審校)
斯模組者,所以運{{lua}}模板也。
斯模組不可直任於維基文,必借{{lua}}模板而後可假之。欲究其理,當考其疏。
由 Lua 模組役之
[纂]欲由他 Lua 模組以役斯局,必先引之:
local mLuaBanner = require('Module:Lua banner')
既引,乃可假其綱紀以生邊框也:
mLuaBanner._main(args)
--本模組嵌入模板{{lua}}
local yesno = require('Module:Yesno')
local mList = require('Module:List')
local mTableTools = require('Module:TableTools')
local mMessageBox = require('Module:Message box')
local p = {}
function p.main(frame)
local origArgs = frame:getParent().args
local args = {}
for k, v in pairs(origArgs) do
v = v:match('^%s*(.-)%s*$')
if v ~= '' then
args[k] = v
end
end
return p._main(args)
end
function p._main(args)
local modules = mTableTools.compressSparseArray(args)
local box = p.renderBox(modules)
local trackingCategories = p.renderTrackingCategories(args, modules)
return box .. trackingCategories
end
function p.renderBox(modules)
local boxArgs = {}
if #modules < 1 then
boxArgs.text = '<strong class="error">誤矣:未指定模組</strong>'
else
local moduleLinks = {}
for i, module in ipairs(modules) do
moduleLinks[i] = string.format('[[:%s]]', module)
end
local moduleList = mList.makeList('bulleted', moduleLinks)
boxArgs.text = '用[[Wikipedia:Lua|Lua語製成]]:\n' .. moduleList
end
boxArgs.type = 'notice'
boxArgs.small = true
boxArgs.image = '[[File:Lua-logo-nolabel.svg|30px|alt=Lua之徽記|link=Wikipedia:Lua]]'
return mMessageBox.main('mbox', boxArgs)
end
function p.renderTrackingCategories(args, modules, titleObj)
if yesno(args.nocat) then
return ''
end
local cats = {}
-- Error category
if #modules < 1 then
cats[#cats + 1] = '模板未指定Lua模組'
end
-- Lua templates category
titleObj = titleObj or mw.title.getCurrentTitle()
local subpageBlacklist = {
doc = true,
sandbox = true,
sandbox2 = true,
testcases = true
}
if titleObj.namespace == 10
and not subpageBlacklist[titleObj.subpageText]
then
local category = args.category
if not category then
local categories = {
['Module:String'] = '模板而基於Lua字符串者',
['Module:Math'] = '模板而基於Lua數學模組者',
['Module:BaseConvert'] = '模板而基于Lua模組BaseConvert者',
['Module:Citation'] = '引用模板而基于Lua者'
}
categories['Module:Citation/CS1'] = categories['Module:Citation']
category = modules[1] and categories[modules[1]]
category = category or '模板而基於Lua語者'
end
cats[#cats + 1] = category
end
for i, cat in ipairs(cats) do
cats[i] = string.format('[[分類:%s]]', cat)
end
return table.concat(cats)
end
return p