Перейти к содержанию

Модуль:Краткий вызов: различия между версиями

Материал из LemonCraft Wiki
Новая страница: «p = {} p.shortcut = function(f) local args = require("Модуль:ProcessArgs").norm() local result = mw.html.create("table") result:addClass("noprint") result:addClass("shortcut") result:attr("cellspacing", "0") local tableRow = result:tag("tr") local firstCell = tableRow:tag("td") firstCell:addClass("shortcut-1") firstCell:wikitext("20px|link=|Короткая ссылка-перенаправление|alt=↱")...»
м 1 версия импортирована
 
(не показаны 2 промежуточные версии 2 участников)
Строка 1: Строка 1:
p = {}
local p = {}


p.shortcut = function(f)
-- Форматирование ссылки
local function formatLink(shortcut, isTemplate)
local link = {'[', nil, ' ', shortcut, ']'}
if isTemplate then
link[1] = '{{['
link[5] = ']}}'
if not shortcut:match(":") then
shortcut = "Шаблон:" .. shortcut
end
end
link[2] = tostring(mw.uri.fullUrl(shortcut, "redirect=no"))
return table.concat(link)
end
 
-- Основная функция
function p.shortcut(f)
local args = require("Модуль:ProcessArgs").norm()
local args = require("Модуль:ProcessArgs").norm()
local result = mw.html.create("table")
-- Шаблон?
result:addClass("noprint")
local asTemplate = (args["шаблон"] or "да") == "да"
result:addClass("shortcut")
result:attr("cellspacing", "0")
local tableRow = result:tag("tr")
-- Стили
local firstCell = tableRow:tag("td")
local tstyles = require("Модуль:TemplateStyles").load("Шаблон:Краткий вызов/styles.css")
firstCell:addClass("shortcut-1")
firstCell:wikitext("[[Файл:Redirectltr.png|20px|link=|Короткая ссылка-перенаправление|alt=↱]]")
local secondCell = tableRow:tag("td")
-- Обёртка
secondCell:addClass("shortcut-2")
local wrapper = mw.html.create("div"):addClass("shortcut-wrapper")
local asTemplate = args["шаблон"] or "да"
-- Заглавие
if (asTemplate == "да") then
wrapper:tag("div"):addClass("shortcut-caption"):wikitext("Сокращения")
for index, value in ipairs(args) do
if index > 1 then
-- Основной блок
secondCell:tag("br")
local main = wrapper:tag("div"):addClass("shortcut-main")
end
secondCell:wikitext(f:expandTemplate({
-- Иконка
["title"] = "ШаблонСсылка",
main:tag("span"):addClass("shortcut-icon"):wikitext(
["args"] = {
"[[Файл:Redirectltr.png|20px|link=|Короткая ссылка-перенаправление|alt=↱|class=darkmode-invert]]"
value
)
}
}))
-- Блок со ссылками
end
local links = main:tag("ul"):addClass("shortcut-links list-style-none")
else
links:addClass(asTemplate and "shortcut-links-template" or "shortcut-links-notemplate")
for index, value in ipairs(args) do
if index > 1 then
-- Ссылки
secondCell:tag("br")
for _, shortcut in ipairs(args) do
end
links:tag("li"):wikitext(formatLink(shortcut, asTemplate))
secondCell:wikitext("[[" .. value .. "]]")
end
end
end
return tostring(result)
return tstyles, tostring(wrapper)
end
end


return p
return p

Текущая версия от 13:23, 30 апреля 2025

Для документации этого модуля может быть создана страница Модуль:Краткий вызов/doc

local p = {}

-- Форматирование ссылки
local function formatLink(shortcut, isTemplate)
	local link = {'[', nil, ' ', shortcut, ']'}
	if isTemplate then
		link[1] = '{{['
		link[5] = ']}}'
		
		if not shortcut:match(":") then
			shortcut = "Шаблон:" .. shortcut
		end
	end
	link[2] = tostring(mw.uri.fullUrl(shortcut, "redirect=no"))
	return table.concat(link)
end

-- Основная функция
function p.shortcut(f)
	local args = require("Модуль:ProcessArgs").norm()
	
	-- Шаблон?
	local asTemplate = (args["шаблон"] or "да") == "да"
	
	-- Стили
	local tstyles = require("Модуль:TemplateStyles").load("Шаблон:Краткий вызов/styles.css")
	
	-- Обёртка
	local wrapper = mw.html.create("div"):addClass("shortcut-wrapper")
	
	-- Заглавие
	wrapper:tag("div"):addClass("shortcut-caption"):wikitext("Сокращения")
	
	-- Основной блок
	local main = wrapper:tag("div"):addClass("shortcut-main")
	
	-- Иконка
	main:tag("span"):addClass("shortcut-icon"):wikitext(
		"[[Файл:Redirectltr.png|20px|link=|Короткая ссылка-перенаправление|alt=↱|class=darkmode-invert]]"
	)
	
	-- Блок со ссылками
	local links = main:tag("ul"):addClass("shortcut-links list-style-none")
	links:addClass(asTemplate and "shortcut-links-template" or "shortcut-links-notemplate")
	
	-- Ссылки
	for _, shortcut in ipairs(args) do
		links:tag("li"):wikitext(formatLink(shortcut, asTemplate))
	end
	
	return tstyles, tostring(wrapper)
end

return p