モジュールの解説[表示] [編集] [履歴] [キャッシュを破棄]

{{ }}

local p = {}

local template = 'テンプレート:Rd' -- name of the template

function p.pickup(number)
    local content = mw.title.new( template .. '/' .. tostring(number) ):getContent()
    local title = string.match( content , "{{.-|title=(.-)[\n ]-|sentences=.-}}" )
    local banner = mw.wikibase.getBestStatements(mw.wikibase.getEntityIdForTitle( title ), 'P948')[1].mainsnak.datavalue.value
    local text = string.match( content , "{{.-|sentences=(.-)[\n ]-}}" )
    return {banner, title, text}
end

function p._rd(frame)
    local infos = {}
	subpages = -1
	repeat
        if subpages ~= -1 then
            table.insert(infos, p.pickup(subpages))
        end
		subpages = subpages + 1 -- start from 0 (Template:rd/0)
	until mw.title.new( template .. '/' .. tostring(subpages) ):getContent() == nil
    return infos -- infos = {{banner1, title1, text1}, {banner2, title2, text2} ... }
end

function p.rd(frame)
    local infos = p._rd(frame)
    local dom = mw.html.create( 'div' )
    	:addClass( "mainpage-grid mainpage-rd-grid" )
    	:attr( "ontouchstart", "" )
    for i = 1, #infos do
    	dom = dom
    		:tag( 'div' )
    		:addClass( "mainpage-rd-0 mainpage-grid-item" )
    			:tag( 'p' )
    				:wikitext( "[[ファイル:" .. infos[i][1] .. "|frameless|1000px]]" )
    				:done()
    			:tag( 'p' )
    				:addClass( "mainpage-grid-text" )
    				:cssText( "display:-webkit-box;-webkit-line-clamp:2;line-clamp:2;-webkit-box-orient:vertical" )
    				:wikitext( infos[i][3] )
    				:done()
    		:done()
        i = i + 1
    end
    dom = dom:allDone()
    return dom
end

return p