Jump to content

Module:Testcase table

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Frietjes (talk | contribs) at 17:54, 12 August 2013. 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.ustring.gsub(mw.title.getCurrentTitle().text, '/.*$', '');
    local template1 = args['_template1'] or args['_template'] or (basepagename)
    local template2 = args['_template2'] or (template1 .. '/sandbox')
    local heading1 = args['_heading1'] or '{{[[Template:' .. template1 .. '|' .. template1 ..']]}}'
    local heading2 = args['_heading2'] or '{{[[Template:' .. template2 .. '|' .. template2 ..']]}}'
    local caption = args['_caption'] or 'Side by side comparison'
    local t = {}
    
    for k, v in pairs(args) do
        t[k] = v
    end
    
    return mw.ustring.format( [==[
<table><caption>%s</caption>
<tr><th style="width:50%%">%s</th><th style="width:50%%">%s</th></tr>
<tr style="vertical-align:top"><td>
%s</td><td>
%s</td></tr></table>]==],
        caption,
        heading1, heading2,
        frame:expandTemplate{ title = template1, args = t },
        frame:expandTemplate{ title = template2, args = t }
    )
end

return p