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 config = require('Module:CareerList/config') |
|||
-- |
-- Функция для определения ссылки на сайт |
||
function p.getSiteLink(site) |
|||
local config = mw.loadData('Module:CareerList/config') |
|||
-- проверка наличия значения в конфигурационном файле |
|||
site = site:lower() |
|||
if config[site] then |
|||
error(string.format('Сайт %s не найден в конфигурационном файле', site)) |
|||
local url = config[site].url |
|||
end |
|||
local id = mw.text.encode(site.id) |
|||
return string.format('[%s %s]', url:gsub('$1', id), site) |
|||
-- замена переменной $1 на значение id |
|||
else |
|||
local url = config.sites[site].url:gsub('%$1', id) |
|||
return site |
|||
end |
|||
-- возврат ссылки |
|||
return string.format('[[%s|%s]]', url, site) |
|||
end |
end |
||
-- |
-- Функция для создания верхней части таблицы |
||
function p.makeTableTop() |
|||
return mw.html.create('table') |
|||
-- определение цвета фона ячейки 1 |
|||
:addClass('wikitable sortable') |
|||
local bg |
|||
:css('width', '100%') |
|||
:css('text-align', 'center') |
|||
:tag('tr') |
|||
elseif site == 'Website' then |
|||
:tag('th'):css('width', '25%'):wikitext('Студия'):done() |
|||
bg = '#E7E7E7' |
|||
:tag('th'):css('width', '25%'):wikitext('Идентификатор'):done() |
|||
else |
|||
:tag('th'):css('width', '25%'):wikitext('Название'):done() |
|||
error(string.format('Значение site (%s) должно быть "Studio" или "Website"', site)) |
|||
:tag('th'):css('width', '25%'):wikitext('Примечания'):done() |
|||
end |
|||
:done() |
|||
-- определение значения alias |
|||
if alias == '' then |
|||
alias = config.sites[site].name |
|||
end |
|||
-- определение значения notes |
|||
if notes == '' then |
|||
notes = 'N/A' |
|||
end |
|||
-- создание ячейки |
|||
local cell = string.format('|-\n| style="background-color: %s;" | %s\n| %s\n| %s\n| %s', bg, site, getSiteLink(site, id), alias, notes) |
|||
return cell |
|||
end |
end |
||
-- Функция для создания ячейки таблицы |
|||
-- экспорт функций |
|||
function p.makeCell(cellType, site, id, alias, notes) |
|||
return { |
|||
local function getColor(index) |
|||
getSiteLink = getSiteLink, |
|||
return (index % 2 == 0) and '#F3F3F3' or '#FFFFFF' |
|||
makeCell = makeCell |
|||
end |
|||
} |
|||
local function getBackground(site) |
|||
local config = mw.loadData('Module:CareerList/config') |
|||
local color = (cellType == 'Studio') and '#DADADA' or '#E7E7E7' |
|||
return config[site] and color or '#FFFFFF' |
|||
end |
|||
local function getAlias(alias, title) |
|||
if not alias or alias == '' then |
|||
return title |
|||
else |
|||
return alias |
|||
end |
|||
end |
|||
local function getNotes(notes) |
|||
if not notes or notes == '' then |
|||
return 'N/A' |
|||
else |
|||
return notes |
|||
end |
|||
end |
|||
local background = getBackground(site) |
|||
local cell = mw.html.create('td') |
|||
:css('background-color', background) |
|||
:css('padding', '8px') |
|||
:wikitext(p.getSiteLink(site)) |
|||
:done() |
|||
local idCell = mw.html.create('td') |
|||
:css('background-color', background) |
|||
:css('padding', '8px') |
|||
:wikitext(id) |
|||
:done() |
|||
local aliasCell = mw.html.create('td') |
|||
:css('background-color', background) |
|||
:css('padding', '8px') |
|||
:wikitext(getAlias(alias, mw.title.getCurrentTitle().text)) |
|||
:done() |
|||
local notesCell = mw.html.create('td') |
|||
:css('background-color', background) |
|||
:css('padding', '8px') |
|||
:wikitext(getNotes(notes)) |
|||
:done() |
|||
return mw.html.create('tr') |
|||
:css('background-color', getColor()) |
|||
:node(cell) |
|||
:node(idCell) |
|||
:node(aliasCell) |
|||
:node(notesCell) |
|||
:done() |
|||
end |
|||
return p |
|||
Revision as of 23:53, 12 March 2023
Documentation for this module may be created at Module:CareerList/doc
local p = {}
-- Функция для определения ссылки на сайт
function p.getSiteLink(site)
local config = mw.loadData('Module:CareerList/config')
site = site:lower()
if config[site] then
local url = config[site].url
local id = mw.text.encode(site.id)
return string.format('[%s %s]', url:gsub('$1', id), site)
else
return site
end
end
-- Функция для создания верхней части таблицы
function p.makeTableTop()
return mw.html.create('table')
:addClass('wikitable sortable')
:css('width', '100%')
:css('text-align', 'center')
:tag('tr')
:tag('th'):css('width', '25%'):wikitext('Студия'):done()
:tag('th'):css('width', '25%'):wikitext('Идентификатор'):done()
:tag('th'):css('width', '25%'):wikitext('Название'):done()
:tag('th'):css('width', '25%'):wikitext('Примечания'):done()
:done()
end
-- Функция для создания ячейки таблицы
function p.makeCell(cellType, site, id, alias, notes)
local function getColor(index)
return (index % 2 == 0) and '#F3F3F3' or '#FFFFFF'
end
local function getBackground(site)
local config = mw.loadData('Module:CareerList/config')
local color = (cellType == 'Studio') and '#DADADA' or '#E7E7E7'
return config[site] and color or '#FFFFFF'
end
local function getAlias(alias, title)
if not alias or alias == '' then
return title
else
return alias
end
end
local function getNotes(notes)
if not notes or notes == '' then
return 'N/A'
else
return notes
end
end
local background = getBackground(site)
local cell = mw.html.create('td')
:css('background-color', background)
:css('padding', '8px')
:wikitext(p.getSiteLink(site))
:done()
local idCell = mw.html.create('td')
:css('background-color', background)
:css('padding', '8px')
:wikitext(id)
:done()
local aliasCell = mw.html.create('td')
:css('background-color', background)
:css('padding', '8px')
:wikitext(getAlias(alias, mw.title.getCurrentTitle().text))
:done()
local notesCell = mw.html.create('td')
:css('background-color', background)
:css('padding', '8px')
:wikitext(getNotes(notes))
:done()
return mw.html.create('tr')
:css('background-color', getColor())
:node(cell)
:node(idCell)
:node(aliasCell)
:node(notesCell)
:done()
end
return p