Module:CareerList
Jump to navigation
Jump to search
Documentation for this module may be created at Module:CareerList/doc
local p = {} function p.main(frame) local config = mw.loadData('Модуль:CareerList/config') local args = frame:getParent().args local list = args.list or '' local output = {} local site_colors = { -- цвета фона ячеек website = '#E7E7E7', studio = '#DADADA' } local color_count = 0 local row_color = {} local function get_color() color_count = color_count + 1 if color_count % 2 == 0 then return '#F3F3F3' else return '#FFFFFF' end end local function get_site_color(site) return site_colors[config[site].type] end local function get_site_name(site) return config[site].name end local function get_site_url(site, id) local url = config[site].url return mw.ustring.gsub(url, '%$1', id) end local function get_alias(alias, page_title) if alias and alias ~= '' then return alias else return page_title end end local function get_notes(notes) if notes and notes ~= '' then return notes else return 'N/A' end end for row in mw.ustring.gmatch(list, '%{%{CareerList%|(.+)%}%}') do local cells = {} local values = mw.text.split(row, '|') local site = mw.ustring.lower(values[2]) local id = values[3] local alias = values[4] local notes = values[5] local page_title = mw.title.getCurrentTitle().text if not config[site] then error('Invalid site: ' .. site) end local site_color = get_site_color(site) table.insert(row_color, site_color) table.insert(cells, '<td style="background-color:' .. site_color .. '; text-align:center;">' .. get_site_name(site) .. '</td>') table.insert(cells, '<td style="background-color:' .. get_color() .. ';"><a href="' .. get_site_url(site, id) .. '">' .. get_alias(alias, page_title) .. '</a></td>') table.insert(cells, '<td style="background-color:' .. get_color() .. ';">' .. get_notes(notes) .. '</td>') table.insert(output, '<tr>' .. table.concat(cells) .. '</tr>') end local header = args.header or '' local style = 'style="background-color:#F2F2F2;"' local table_header = '<table class="wikitable" style="width:100%;">' .. '<tr ' .. style .. '><th colspan="3">' .. header .. '</th></tr>' .. '<tr ' .. style .. '><th>' .. config.website.name .. '</th><th>' .. config.studio.name .. '</th><th>Notes</th></tr>' local table_footer = '</table>' return table_header .. table.concat(output) .. table_footer end return p