コンテンツにスキップ

あくまで管理人個人が勝手に書き殴っているメモなので、誤謬・誤植・誤解も含め、記述内容の正確性を一切保証しません。責任を負いません。問い合わせ等を受け付けません

これは、このWebサイトの読者が、このWebサイトにある記述内容を一方的・盲目的に信用したことが原因で、読者に事故や損害を与えた場合も含みます。万が一にも参考にする場合は、事前に読者による計算や実験を必須とします。ここでいう計算や実験が何であるかを理解できていない方は、まずそれを理解することから始めて下さい。なお、このWebサイトには、計算や実験が何であるかを理解できるような記述はありません。

各戸に引き込まれている商用電力はもちろん、市販されている電池を電源として使う場合でも、計算や操作の僅かなミスが事故や損害に繋がります。くれぐれも注意して下さい。

モジュール:Lua banner

提供: アナログ回路研究資料
2019年10月6日 (日) 09:39時点におけるWebmaster (トーク | 投稿記録)による版 (1版 をインポートしました)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)

このモジュールについての説明文ページを モジュール:Lua banner/doc に作成できます

-- {{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]]モジュールを使用しています:' .. moduleList
	end
	boxArgs.type = 'notice'
	boxArgs.small = true
	boxArgs.image = '[[File:Lua-logo-nolabel.svg|30px|alt=Lua logo|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] = ''
	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'] = '',
				['Module:Math'] = '',
				['Module:BaseConvert'] = '',
				['Module:Citation'] = ''
			}
			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('[[Category:%s]]', cat)
	end
	return table.concat(cats)
end

return p