יחידה:בוט ההסבה/הדגמה

ניתן ליצור תיעוד על היחידה הזאת בדף יחידה:בוט ההסבה/הדגמה/תיעוד

local p = {}

function p.toggleTable(frame)
    local showTable = frame.args.show == 'true'
    local buttonLabel = showTable and 'Hide Table' or 'Show Table'
    local tableRows = showTable and p.getTableRows(frame) or ''
    
    local button = mw.html.create('span')
        :addClass('button')
        :wikitext(buttonLabel)
        :cssText('cursor:pointer')
        :cssText('padding:0.2em 0.4em')
        :cssText('border:1px solid #ccc')
        :cssText('border-radius:4px')
        :attr('onclick', 'toggleTable()')

    local result = mw.html.create('div')
        :wikitext(tostring(button))
        :wikitext(tableRows)

    return tostring(result)
end

function p.getTableRows(frame)
    local code = frame.args['קוד'] or ''
    local result = frame.args['תוצאה'] or ''

    local table = mw.html.create('table')
        :addClass('wikitable')
        :css('border-collapse', 'collapse')
        
    -- Table Header
    table:tag('tr')
        :tag('th'):wikitext('קוד'):done()
        :tag('th'):wikitext('תוצאה'):done()
        :done()

    -- Table Body
    table:tag('tr')
        :tag('td'):wikitext('<code dir="rtl" style="display:inline-block;">' .. code .. '</code>'):done()
        :tag('td'):wikitext('<code dir="rtl" style="display:inline-block;">' .. result .. '</code>'):done()
        :done()

    return tostring(table)
end

return p