Module documentation
[create]
The documentation for this module is missing. Click here to create it.
local Ruby = {}
local getArgs = require('Dev:Arguments').getArgs
local HF = require('Module:HF')
function Ruby.ruby (frame)
local args = getArgs(frame, {
trim = true,
removeBlanks = false
})
return Ruby._ruby(args)
end
function Ruby._ruby (args)
local rubytag = mw.html.create('ruby')
local lang = args['lang'] or 'ja'
local link = args['link']
rubytag:addClass('rubytext'):addClass('ruby-'..lang):attr('lang', lang)
for i,v in ipairs(args) do
--if (i % 2 ~= 0) and (type(args[i + 1]) ~= string) then
-- rubytag:wikitext(v)
--else
if (i % 2 ~= 0) then
rubytag:tag('rb'):wikitext(v):done()
elseif (i % 2 == 0) and
((type(v) == nil) or
mw.ustring.len( mw.text.trim( v ) ) == 0)
then
else
rubytag:tag('rp'):wikitext(' ('):done()
rubytag:tag('rt'):wikitext(v):done()
rubytag:tag('rp'):wikitext(') '):done()
end
end
rubytag:allDone()
return link and HF.Link(link, tostring(rubytag)) or tostring(rubytag)
--[==[
{{ #if: {{{2<includeonly>|</includeonly>}}}
| <ruby class="rubytext ruby-{{{lang|ja}}}" lang="{{{lang|ja}}}"><rb>{{{1}}}</rb><rp>(</rp><rt>{{{2}}}</rt><rp>)</rp></ruby>
| {{{1}}}[[Category:Pages with an unnecessary ((Ruby)) transclusion]]
}}{{ #if: {{{1<includeonly>|</includeonly>}}} || [[Category:Pages with an unnecessary ((Ruby)) transclusion]]
}}{{ #ifeq: {{{3|¬}}} | ¬ || [[Category:((Ruby)) transclusions with too many parameters]] }}
--]==]
end
function Ruby.split( frame )
--
-- implements {{Ruby/split}}
--
if frame == mw.getCurrentFrame() then
args = frame:getParent().args
else
args = frame
end
if not args[1] then
return
end
args[1] = mw.text.trim( args[1] )
if not mw.ustring.find( args[1], '<ruby' ) then
return args[1]
end
args[2] = args[2] and ( mw.text.trim( args[2] ) == 'base' and '' or mw.text.trim( args[2] ) ) or ''
local first, parts, match
first = mw.ustring.match( args[1], '^(.-)<ruby' ) or ''
parts = mw.text.split( args[1], '<ruby' )
match = args[2] == '' and '<rb[^>]*>(.-)</rb>' or '<rt[^>]*>(.-)</rt>'
for i = 1, #parts do
parts[i] = ( mw.ustring.match( parts[i], match ) or '' )
.. ( mw.ustring.match( parts[i], '</ruby>(.*)$' ) or '' )
end
return first, table.concat( parts, '' )
end
return Ruby