モジュール:サンドボックス/Q8j/Template:Cite web

モジュールの解説[作成]
local p = {}
function p.Main(frame)
	local cite_1 = '<cite style="font-style:normal" '
		local cite_2_a = '' -- 2_aは、last、author、publisherに何かあるか順に確認し、あった場合は代入する処理
			if frame.args['last'] ~= '' then -- 「last」に何かある場合
				cite_2_a = frame.args['last']
			elseif frame.args['author'] ~= '' then -- 「author」に何かある場合
				cite_2_a = frame.args['author']
			elseif frame.args['publisher'] ~= '' then -- 「publisher」に何かある場合(本来は不要な判定だが、エラーが出ないように念のため。後で要検討)
				cite_2_a = frame.args['publisher']
			end
		local cite_2_b = '' -- 2_bは、year、dateに何かあるか順に確認し、あった場合は代入する処理
			if frame.args['year'] ~= '' then
				cite_2_b = frame.args['year']
			elseif frame.args['date'] ~= '' then
				cite_2_b = frame.args['date']
			end
	local cite_2 = ''
		if frame.args['ref'] == '' or frame.args['ref'] == 'none' then -- 空か、「none」の場合、何もしない
		elseif frame.args['ref'] == 'harv' then -- harvだった場合、cite_2_a、cite_2_bを繋げてanchorエンコード
			cite_2 = 'id="CITEREF' .. mw.uri.anchorEncode( cite_2_a .. cite_2_b ) .. '"'
		else -- それ以外の場合、「ref」
			cite_2 = 'id="' ..  mw.uri.anchorEncode( frame.args['ref'] ) .. '"'
		end
	local cite_3 = ''
		if frame.args['url'] == '' then
			if frame.args['title'] == '' then
				cite_3 = ' <strong class="error">[[Template:Cite web]]の呼び出しエラー:' .. "引数''' url '''と''' title '''は必須です。</strong>"
			else 
				cite_3 = ' <strong class="error">[[Template:Cite web]]の呼び出しエラー:' .. "引数''' url '''は必須です。</strong>"
			end
		elseif frame.args['title'] == '' then
			cite_3 = ' <strong class="error">[[Template:Cite web]]の呼び出しエラー:' .. "引数''' title '''は必須です。</strong>"
		end
end
return p