Module:CareerList: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
PeaceDeadC (talk | contribs) No edit summary |
PeaceDeadC (talk | contribs) No edit summary |
||
| Line 1: | Line 1: | ||
local p = {} |
local p = {} |
||
| ⚫ | |||
-- load configuration from a separate file |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
local alias = args.alias or args[1] |
|||
| ⚫ | |||
-- получаем конфигурацию сайтов |
|||
-- helper function to get the config value for a site |
|||
| ⚫ | |||
local function getConfigValue(site, key) |
|||
local siteData = sites[site] |
|||
| ⚫ | |||
if not siteData then |
|||
-- helper function to format the alias or notes field |
|||
| ⚫ | |||
local function formatText(text) |
|||
| ⚫ | |||
return text ~= '' and text or 'N/A' |
|||
end |
|||
-- заменяем переменную $1 в URL на значение id |
|||
-- helper function to generate the table row |
|||
local url = siteData.url:gsub('%$1', id) |
|||
local function generateTableRow(site, id, alias, notes, rowColor) |
|||
local siteColor = getConfigValue(site, 'color') |
|||
-- формируем ссылку |
|||
local cellColor = site == 'Website' and '#E7E7E7' or '#DADADA' |
|||
local |
local link = string.format('[%s %s]', url, args.site) |
||
local siteStyle = string.format('background-color: %s;', siteColor or cellColor) |
|||
-- формируем ячейки таблицы |
|||
| ⚫ | |||
local |
local cells = { |
||
siteData.label, |
|||
| ⚫ | |||
link, |
|||
alias, |
|||
notes |
|||
<td style="%s"><a href="%s">%s</a></td> |
|||
| ⚫ | |||
<td style="%s">%s</td> |
|||
<td style="%s">%s</td> |
|||
-- возвращаем сформированную строку таблицы |
|||
| ⚫ | |||
| ⚫ | |||
]], rowStyle, siteStyle, siteName, cellColor, url, site, cellColor, alias, cellColor, formatText(notes)) |
|||
end |
end |
||
function p.CareerListTop(frame) |
|||
| ⚫ | |||
local args = frame.args |
local args = frame.args |
||
local list = args.list or '' |
local list = args.list or '' |
||
| ⚫ | |||
| ⚫ | |||
local rowColor = '#FFFFFF' |
|||
{| class="wikitable" |
|||
for row in mw.text.gsplit(list, '%{%{CareerList') do |
|||
|+ %s |
|||
local params = mw.text.split(row, '|') |
|||
! Категория |
|||
local site = params[2] or '' |
|||
! Ссылка |
|||
| ⚫ | |||
! Псевдоним |
|||
local alias = params[4] or mw.title.getCurrentTitle().text |
|||
! Заметки |
|||
| ⚫ | |||
%s]=], args.title or '', list) |
|||
rows = rows .. generateTableRow(site, id, alias, notes, rowColor) |
|||
rowColor = rowColor == '#FFFFFF' and '#F3F3F3' or '#FFFFFF' |
|||
| ⚫ | |||
local tableStyle = 'background-color: #F2F2F2; width: 100%;' |
|||
| ⚫ | |||
end |
end |
||
Revision as of 18:22, 12 March 2023
Documentation for this module may be created at Module:CareerList/doc
local p = {}
function p.CareerList(frame)
local args = frame.args
local site = string.lower(args.site)
local id = args.id or ''
local alias = args.alias or args[1]
local notes = args.notes or 'N/A'
-- получаем конфигурацию сайтов
local sites = mw.loadData('Module:CareerList/config')
local siteData = sites[site]
if not siteData then
return ''
end
-- заменяем переменную $1 в URL на значение id
local url = siteData.url:gsub('%$1', id)
-- формируем ссылку
local link = string.format('[%s %s]', url, args.site)
-- формируем ячейки таблицы
local cells = {
siteData.label,
link,
alias,
notes
}
-- возвращаем сформированную строку таблицы
return string.format('|-\n| %s || %s || %s || %s', unpack(cells))
end
function p.CareerListTop(frame)
local args = frame.args
local list = args.list or ''
return string.format([=[
{| class="wikitable"
|+ %s
! Категория
! Ссылка
! Псевдоним
! Заметки
%s]=], args.title or '', list)
end
return p