FANDOM


local p = {}
 
local getArgs
local scheme
 
-- getColorScheme()
-- @...{string(s)}
local function getColorTable(colorKey)
    local default = scheme.others['표']
 
    if colorKey == nil then return default end
 
    for category, dataset in pairs(scheme) do
        for key, value in pairs(dataset) do
            if key == colorKey then
                return value
            end
        end
    end
 
    return default
end
 
-- formatRowData()
-- @args{table}
-- @prefixes{table}
local function formatRowData( args, prefixes )
    local key, val, nextKey, nextVal, nextExists
    local vals = {}
    local index, nextIndex = 1
 
    repeat
        nextIndex = index + 1
        nextExists = false
        vals[index] = {}
 
        for i = 1, #prefixes do
            key = prefixes[i] .. index
            val = args[key]
            vals[index][i] = val or ''
 
            nextKey = prefixes[i] .. nextIndex
            nextExists = args[nextKey] and true
        end
 
        index = nextIndex
    until( not nextExists )
 
    return vals
end
 
function p.main( frame )
    if not getArgs then
        getArgs = require( 'Module:Arguments' ).getArgs
    end
    if not scheme then
        scheme = mw.loadData( 'Module:Color/Scheme' )
    end
 
    local args = getArgs( frame )
    local theadData = { '나라', '이름', '유래' }
    local tbodyData = formatRowData( args, theadData )
    local tblData = { theadData }
    local tbl, thead, trow, tcell
    local primaryColor, secondaryColor
 
    primaryColor = getColorTable( args['타입1'] )
    if not args['타입2'] then
        secondaryColor = primaryColor
    else
        secondaryColor = getColorTable( args['타입2'] )
    end
 
 
    tbl = mw.html.create('table')
    tbl:addClass( 'rounded text-center' )
    tbl:css( 'background', primaryColor[3] )
    tbl:css( 'border', '4px solid ' .. secondaryColor[2] )
 
    thead = tbl:tag( 'tr' ):css( 'background', primaryColor[1] )
    for i = 1, #theadData do
        thead:tag( 'th' ):wikitext( theadData[i] )
    end
 
    for i = 1, #tbodyData do
        trow = tbl:tag( 'tr' ):addClass( 'bg-white' )
        tcell = tbodyData[i]
        for i = 1, #tcell do
            trow:tag( 'td' ):wikitext( tcell[i] )
        end
    end
 
    return tbl:done()
end
 
return p
Community content is available under CC-BY-SA unless otherwise noted.