Jump to content

Module:Testcase table

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 14:29, 4 July 2013 (try some performance tweaks (although the old version looked pretty fast too)). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
--
-- This module will implement {{Testcase table}}
--
local p = {}

function p.testcase(frame)
    local args = frame:getParent().args
    local basepagename = mw.title.getCurrentTitle().rootText
    args['_template1'] = args['_template1'] or (basepagename)
    args['_template2'] = args['_template2'] or (basepagename .. '/sandbox')
    args['_heading1'] = args['_heading1'] or '{{[[Template:' .. args['_template1'] .. '|' .. args['_template1'] ..']]}}'
    args['_heading2'] = args['_heading2'] or '{{[[Template:' .. args['_template2'] .. '|' .. args['_template2'] ..']]}}'
    args['_caption'] = args['_caption'] or 'Side by side comparison'
    
    local res1 = frame:expandTemplate{ title = args['_template1'], args = args }
    local res2 = frame:expandTemplate{ title = args['_template2'], args = args }
    
    return mw.ustring.format( [==[
<table><caption>%s</caption>
<tr><th style="width:50%%">%s</th><th style="width:50%%">%s</tr>
<tr style="vertical-align:top"><td>
%s</td><td>
%s</td></tr></table>]==],
        args['_caption'],
        args['_heading1'], args['_heading2'],
        res1,
        res2
    )
end

return p