Модуль:Песочница/Pok: различия между версиями

мНет описания правки
Нет описания правки
 
(не показаны 64 промежуточные версии этого же участника)
Строка 1: Строка 1:
-- Загрузка данных
local p = {}
local accentData = mw.loadData("Модуль:IanComradeBot/prototypes/accent.json/data")
local getArgs = require('Module:Arguments').getArgs


local p = {}
function p.main(frame)
    local args = getArgs(frame, { removeBlanks = false })
    local name = args[1] or ""
    local attributes = args[2] or ""
    if name == "" then
        return "<span class=\"error\">Ошибка: не указано имя файла.</span>"
    end
    local ext = (args["ext"] or "png"):gsub("^%.", "")
    local namespace = args["namespace"] or "Файл"
    local max = tonumber(args["max"]) or 50
    local include_base = (args["base"] ~= "no")
 
    local found = {}


function p.table(frame)
    if include_base then
    local targetId = frame.args[1] or ""
        local t = mw.title.new("Файл:" .. name .. "." .. ext)
    if targetId == "" then
        if t and t.exists then
         return "Ошибка: не указан параметр id."
            table.insert(found, "")
         end
     end
     end


     local foundData = nil
     for i = 1, max do
    for _, item in ipairs(accentData) do
        local t = mw.title.new("Файл:" .. name .. "-" .. i .. "." .. ext)
         if item.id == targetId then
         if t and t.exists then
             foundData = item
             table.insert(found, "-" .. i)
            break
         end
         end
     end
     end


     if not foundData then
     if #found == 0 then
         return "Ошибка: данные по id '" .. targetId .. "' не найдены."
         return ""
     end
     end


     local output = {}
     local before = "[[" .. namespace .. ":" .. name
     table.insert(output, '{| class="sortable-grid sortable-grid--small-column sortable"')
     local after = "." .. ext .. "|" .. attributes .. "]]"
    table.insert(output, '! Сортировка (по алфавиту)')
    table.insert(output, '|-')


     for key, value in pairs(foundData.wordReplacements) do
     local parts = {}
        table.insert(output, "|")
    table.insert(parts, "<choose before=\"" .. before .. "\" after=\"" .. after .. "\">")
        table.insert(
    for _, suf in ipairs(found) do
            output,
         table.insert(parts, "<option>" .. suf .. "</option>")
            frame:preprocess(
                string.format(
                    "{{Cut-Layout|arrow=1|background-color=var(--bg-color-message-subtle)|{{#invoke:Ftl|main|translation|%s}}|{{#invoke:Ftl|main|translation|%s}}}}",
                    key,
                    value
                )
            )
        )
         table.insert(output, "|-")
     end
     end
    table.insert(parts, "</choose>")


     table.insert(output, '|}')
     return frame:preprocess(table.concat(parts, "\n"))
    return table.concat(output, "\n")
end
end


return p
return p