ഘടകം:Super Over

വിക്കിപീഡിയ, ഒരു സ്വതന്ത്ര വിജ്ഞാനകോശം.

ഈ ഘടകത്തിന്റെ വിവരണം ഘടകം:Super Over/വിവരണം എന്ന താളിൽ നിർമ്മിക്കാവുന്നതാണ്

--
-- This module will implement {{Super Over}}
--

local p = {}
local args

local function getArgs(frame)
    local parent_args = frame:getParent().args;
    local args = {}

    for k, v in pairs(parent_args) do
        if v ~= '' then args[k] = v end
    end
    return args;
end

function addTableRow(tbl, small)
    local row = tbl:tag('tr')
    if small then
        row:css('font-size', '85%')
        end
    return row
end

function renderScores(tbl)
    local scoreRow = addTableRow(tbl, true)
    scoreRow:tag('th')
    scoreRow:tag('th'):css('border-right-style', 'hidden')
    scoreRow:tag('th'):wikitext('Total')
    scoreRow:tag('th'):wikitext(args.Score1)
    scoreRow:tag('th'):css('border-right-style', 'hidden')
    scoreRow:tag('th'):wikitext('Total')
    scoreRow:tag('th'):wikitext(args.Score2)
end

function renderDelivery(tbl, b)
    local ball = "B" .. tostring(b)
    local bat1 = args[ball .. "T1Bat"]
    local bat2 = args[ball .. "T2Bat"]
    local bowl1, bowl2, run1, run2

    if bat1 then
        bowl1 = args.Team2Bowler
        run1 = args[ball .. "T1Run"]
    end
    if bat2 then
        bowl2 = args.Team1Bowler
        run2 = args[ball .. "T2Run"]
    end
    if not run1 and not run2 then return false end

    local deliveryRow = addTableRow(tbl, true)
    if b ~= 1 then
        deliveryRow:css('border-top-style', 'hidden')
    end
    deliveryRow:tag('td'):wikitext(tostring(b))

    deliveryRow:tag('td'):wikitext(bowl1)
    deliveryRow:tag('td'):wikitext(bat1)
    deliveryRow:tag('td'):wikitext(run1)

    deliveryRow:tag('td'):wikitext(bowl2)
    deliveryRow:tag('td'):wikitext(bat2)
    deliveryRow:tag('td'):wikitext(run2)

    return true
end
 
function renderHeading(frame, tbl)
    local titleRow = addTableRow(tbl, false)

    local source = args.source
        or frame:expandTemplate{ title = 'citation needed',
            args = { reason='No source parameter defined', date=os.date('%B %Y') } }

    titleRow:tag('th')
        :attr('colspan', '7')
        :css('border', 'none')
        :wikitext('[[Super Over]]' .. source)
        
    local teamsRow = addTableRow(tbl, true)
    local headerRow = addTableRow(tbl, true)

    teamsRow:tag('th')
        :attr('rowspan', '2')
        :css('width', '10%')
        :wikitext('Delivery')
    for i = 1, 2 do
        teamsRow:tag('th')
            :attr('colspan', '3')
            :wikitext(args["Team" .. tostring(i)])
        headerRow:tag('th'):css('width', '19%'):wikitext('Bowler')
        headerRow:tag('th'):css('width', '19%'):wikitext('Batter')
        headerRow:tag('th'):css('width', '7%'):wikitext('Runs')
    end
end

function p.superOver(frame)
    args = getArgs(frame)

    local tbl = mw.html.create('table')
        :addClass('wikitable')
        :addClass('collapsible')
        :addClass(args.state or 'collapsed')
        :css('text-align', 'center')
        :css('width', '100%')
        :css('border', 'none')
        :css('margin', '0')
 
    renderHeading(frame, tbl)
    local i = 1
    local ball
    while true do
        if not renderDelivery(tbl, i) then break end
        i = i + 1
    end
    renderScores(tbl)

    return tostring(tbl)
end

return p
"https://ml.wikipedia.org/w/index.php?title=ഘടകം:Super_Over&oldid=3141177" എന്ന താളിൽനിന്ന് ശേഖരിച്ചത്