モジュール:CargoQuery

提供:Noita Wiki
ナビゲーションに移動 検索に移動

このモジュールでは、|format=templateを回避することで、Cargoにある|no htmlのバグを回避できます。

使用するには、クエリ引数の前にq?を付けます。 テーブルを1つだけ使用している場合でも、|q?tables=を使用してください。

|template=を使用して、クエリ結果の各行を処理するテンプレートを指定する必要があります。 更に|intro=, |outro=, |delimiter=, |default=を指定できます。

すべてのクエリパラメータのLua名を使用するため、|q?join=, |q?groupBy, etcを使用します。

コードを簡単にするために、名前付きargsパラメーターはYesである必要があり、指定する必要はありません。

|format=templateとは異なり、このラッパーは、代わりにスペースを使用するためにアンダースコアを含むパラメーターの名前を変更しません。


パラメータ & 呼び出し

{{#invoke:CargoQuery|main
|q?tables= 	<!-- corresponds to table / tables -->
|q?join= 	<!-- corresponds to join on -->
|q?fields= 	<!-- corresponds to fields -->
|q?where= 	<!-- corresponds to where -->
|q?groupBy= 	<!-- corresponds to group by -->
|q?having= 	<!-- corresponds to having -->
|q?orderBy= 	<!-- corresponds to order by -->
|q?limit= 	<!-- corresponds to limit -->
|template=      <!-- pagename of template (required) -->
|intro=
|outro=
|delimiter=
|default=
}}

依存関係


local p = {}
function p.main(frame)
	local args = frame
	if frame == mw.getCurrentFrame() then
		args = require('Module:ProcessArgs').merge(true)
	else
		frame = mw.getCurrentFrame()
	end
	
	local query = {}
	for k, v in pairs(args) do
		if string.sub(k, 0, 2) == 'q?' then
			query[string.sub(k, 3)] = v
		end
	end
	
	local result = mw.ext.cargo.query(query.tables, query.fields, query)
	if not next(result) then
		return frame:preprocess(args.default or '')
	end
	local tbl = {}
	for _, row in ipairs(result) do
		tbl[#tbl+1] = frame:expandTemplate{ title = args.template, args = row }
	end
	local intro = frame:preprocess(args.intro or '')
	local outro = frame:preprocess(args.outro or '')
	return intro .. table.concat(tbl,args.delimiter or '') .. outro
	
end
return p