由于游戏重置版、怀旧服并存,核对工作量过大,如有错漏请通过B站私信或直接提交更改!

怀旧服相关内容可点击此处或通过菜单栏查看

全站通知:

模块:Ruby

来自约战精灵再临WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索

此模块的文档可以在模块:Ruby/doc创建

local module = {}
local g_frame

function get_arg(name, plain)
	if g_frame.args[name] and (mw.text.trim(g_frame.args[name]) ~= '' or plain) then
		return mw.text.trim(g_frame.args[name])
	end
end

function module.ruby(frame)
	local parent = frame:getParent()
	if parent and (parent:getTitle() == "模板:Ruby" or parent:getTitle() == "模板:Ruby/Sandbox") then
		frame = parent
	end
	g_frame = frame

	local class = get_arg('class')
	local id = get_arg('id')
	local css = get_arg('css')
	local style = get_arg('style') or css
	local rbclass = get_arg('rbclass')
	local rbid = get_arg('rbid')
	local rbsize = get_arg('rbsize')
	local rtclass = get_arg('rtclass')
	local rtid = get_arg('rtid')
	local rtsize = get_arg('rtsize') or '0.75em'
	local rbtext = get_arg(1, true) or '{{{1}}}'
	local rttext = get_arg(2, true) or '{{{2}}}'
	local rblang = get_arg(3)
	local rtlang = get_arg(4) or rblang

	local html = mw.html.create():tag('ruby')
	if class then html:addClass(class) end
	if id then html:attr('id', id) end
	if style then html:cssText(style) end

	local rb = html:tag('rb'):attr('data-id', 'template-ruby')
	if rbclass then rb:addClass(rbclass) end
	if rbid then rb:attr('id', rbid) end
	if rbsize then rb:css('font-size', rbsize) end

	if rblang then
		rb:wikitext( frame:expandTemplate{ title = 'lang', args = { rblang, rbtext } } )
	else
		rb:wikitext(rbtext)
	end
	rb:tag('span'):addClass('template-ruby-hidden'):wikitext('('):done()

	local rt = html:tag('rt')
	if rtclass then rt:addClass(rtclass) end
	if rtid then rt:attr('id', rtid) end
	rt:css('font-size', rtsize)
	if rtlang then
		rt:wikitext( frame:expandTemplate{ title = 'lang', args = { rtlang, rttext } } )
	else
		rt:wikitext(rttext)
	end
	html:tag('span'):addClass('template-ruby-hidden'):wikitext(')'):done()

	return html
end

return module