Модуль:Переключатель проекта: различия между версиями
Материал из Space Station 14 Вики
Pok (обсуждение | вклад) Новая страница: «local p = {} local DEFAULT_VALUE = 'Goob, Corvax' local SPECIAL_SKIP_VALUE = 'Corvax' local function trim(s) return mw.text.trim(s or '') end local function splitProjects(text) local out = {} for part in mw.text.gsplit(text or '', ',', true) do part = trim(part) if part ~= '' then table.insert(out, part) end end return out end local function isSkipValue(value) return mw.ustring.lower(trim(value)) == mw.ustring.lower(SPECIAL_SKIP_VALUE) end...» |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 1: | Строка 1: | ||
local p = {} | local p = {} | ||
local getArgs = require('Module:Arguments').getArgs | |||
local DEFAULT_VALUE = 'Goob, Corvax' | local DEFAULT_VALUE = 'Goob, Corvax' | ||
| Строка 24: | Строка 25: | ||
function p.main(frame) | function p.main(frame) | ||
local | local args = getArgs(frame, { removeBlanks = false }) | ||
local raw = args[1] | |||
if raw == '' then | if raw == '' then | ||
Версия от 19:03, 19 марта 2026
Для документации этого модуля может быть создана страница Модуль:Переключатель проекта/doc
local p = {}
local getArgs = require('Module:Arguments').getArgs
local DEFAULT_VALUE = 'Goob, Corvax'
local SPECIAL_SKIP_VALUE = 'Corvax'
local function trim(s)
return mw.text.trim(s or '')
end
local function splitProjects(text)
local out = {}
for part in mw.text.gsplit(text or '', ',', true) do
part = trim(part)
if part ~= '' then
table.insert(out, part)
end
end
return out
end
local function isSkipValue(value)
return mw.ustring.lower(trim(value)) == mw.ustring.lower(SPECIAL_SKIP_VALUE)
end
function p.main(frame)
local args = getArgs(frame, { removeBlanks = false })
local raw = args[1]
if raw == '' then
raw = DEFAULT_VALUE
end
local projects = splitProjects(raw)
if #projects == 0 then
return ''
end
local first = projects[1]
if isSkipValue(first) then
return ''
end
local result = '{{#vardefine:JsonPath|' .. first .. '}}'
if #projects == 1 then
return result
end
result = result .. '<div style="display:none;" class="js-project-selection-generator">'
.. mw.text.encode(table.concat(projects, ', '))
.. '</div>'
return result
end
return p