2023年政策修订增补工作正在进行中,欢迎参与!
  • Moegirl.ICU:萌娘百科流亡社群 581077156(QQ),欢迎对萌娘百科运营感到失望的编辑者加入
  • Moegirl.ICU:账号认领正在试运行,有意者请参照账号认领流程

Module:CGroupViewer

萌娘百科,万物皆可萌的百科全书!转载请标注来源页面的网页链接,并声明引自萌娘百科。内容不可商用。
跳转到导航 跳转到搜索
Template-info.svg 模块文档  [查看] [编辑] [历史] [刷新]

模板介紹

此模板用于基于模块的公共转换组(CGroup)页面,以展示此转换组的内容。

參數及使用方法

此模板没有参数。

通常无需手工使用此模板,MediaWiki:Scribunto-doc-page-does-not-exist会将其显示于每一个公共转换组模块的上方。但如果一个公共转换组拥有模块文档,此模板不会自动使用,而在模块文档中手工使用此模板可以显示相关内容。

local z = {}
local error = require( 'Module:Error' )

local function makeText( frame, v )
	local text = v.text
	if not v.preprocessed then
		text = frame:preprocess( text )
	end
	return mw.text.trim( text ) .. '\n'
end

local function makeItem( frame, v )
	local text = '* '
	if v.original then
		text = text .. '原文:' .. v.original .. ';'
	end
	text = text .. '-{D|' .. v.rule .. '}-当前显示为:-{|' .. v.rule .. '}-'
	if v.desc ~= nil and v.desc ~= '' then
		text = text .. '<br>说明:' .. v.desc
	elseif v.description ~= nil and v.description ~= '' then
		text = text .. '<br>说明:' .. v.description
	end
	return text .. '\n'
end

function z.main( frame )
	local name = frame.args[1]
	if not name or name == '' then
		return ''
	end
	local data = require( 'Module:CGroup/' .. name )
	if type( data ) ~= 'table' or not data.name or data.name == '' then
		return error.error{ '指定模块“' .. name .. '”不是有效的转换组' }
	end
	if data.name ~= name then
		return frame:expandTemplate{ title = 'Template:CGroup redirect', args = { 'Module:CGroup/' .. data.name } }
	end
	local pieces = { '__NOEDITSECTION__<div class="infoBox" style="width:80%;border-left: 10px solid #1e90ff;"><div class="infoBoxContent"><div class="infoBoxIcon">[[File:Information.svg|25px|link=]]</div><div class="infoBoxText">以下是[[Help:繁简转换/公共转换组|公共转换组]]<b>“' .. data.description .. '”</b>的可读版本,由[[模块:CGroupViewer]]解析。</div></div></div>\n\n' }
	for i, v in ipairs( data.content ) do
		if v.type == 'text' then
			table.insert( pieces, makeText( frame, v ) )
		elseif v.type == 'item' then
			table.insert( pieces, makeItem( frame, v ) )
		end
	end
	table.insert( pieces, '[[分类:公共转换组模块|' .. name .. ']]' )
	return table.concat( pieces )
end

function z.dialog( frame )
	local name = frame.args[1]
	if not name or name == '' then
		return ''
	end
	local data = require( 'Module:CGroup/' .. name )
	local pieces = { '<div class="mw-collapsible mw-collapsed"><span class="plainlinks" style="float: right;">&#91;[',
		tostring( mw.uri.fullUrl( 'Module:CGroup/' .. name, { action = 'edit' } ) ), ' 编辑]&#93;</span>\n',
		'; 本文使用[[Help:繁简转换/公共转换组|公共转换组]]“' .. data.description .. '”。\n',
		'<div class="mw-collapsible-content">\n' }
	for i, v in ipairs( data.content ) do
		if v.type == 'item' then
			table.insert( pieces, makeItem( frame, v ) )
		end
	end
	table.insert( pieces, '</div></div>' )
	return table.concat( pieces )
end

function z.json( frame )
	local name = frame.args[1]
	if not name or name == '' then
		return 'null'
	end
	local data = require( 'Module:CGroup/' .. name )
	local json = require( 'Module:MicroJSON' )
	return json.encode_object( data, {
		name = '',
		description = '',
		content = {
			{ type = '', [true] = '' },
		},
	} )
end

return z