Изменения
Перейти к навигации
Перейти к поиску
Строка 1:
Строка 1:
−
− -- используется для того, чтобы можно было удалять элементы из таблицы
− local function copy(other)
− local res = {}
− for k,v in pairs(other) do
− res[k] = v
− end
− return res
− end
Строка 23:
Строка 14:
− end
−
− --предотвращает обработку вики-текста в отображении образца
− local function nowiki(str)
− local res = str
− str = mw.text.unstripNoWiki(str)
− str = string.gsub(str, '%[', '[')
− str = string.gsub(str, '%]', ']')
− str = string.gsub(str, '<', '<')
− str = string.gsub(str, '>', '>')
− str = string.gsub(str, '{', '{')
− str = string.gsub(str, '|', '|')
− str = string.gsub(str, '}', '}')
− str = string.gsub(str, '\'', ''')
− str = string.gsub(str, '"', '"')
− str = string.gsub(str, '(://)', '<span>%1</span>')
− return str
Строка 53:
Строка 27:
−
− if not getArgs then +
− getArgs = require('Module:Arguments').getArgs
− end
− +
+
+
+
− local container = args._container or nil
− local ucFirst = yesno(args._u, false)
− local link = yesno(args._link, false)
− local endl = args._endl or ''
− local nobr = yesno(args._nobr, false)
− local spaced = yesno(args._spaced, false)
Строка 78:
Строка 46:
+
− +
− +
− if not (tag or container) then +
− container = 'pre'+
− end+
+
+
+
− +
− if not (tag or container) then+
− container = '*pre'+
− end+
− +
− elseif style == 'pre↓' then +
− if not (tag or container) then+
− container = 'pre'+
− end +
− -- содержимое шаблона {{sp↓|50%||-0.5em}}+
− sep = sep or '<div style="margin:-0.5em 50% 0.7em;"><span style="font-size:150%;">↓</span></div>\n'+
− elseif style == '*pre↓' then
− if not (tag or container) then
− container = '*pre'
− end
− -- содержимое шаблона {{sp↓|50%||-0.5em}}
− sep = sep or '<div style="margin:-0.5em 50% 0.7em;"><span style="font-size:150%;">↓</span></div>\n'
− elseif style == 'wikitable' then
− if not (tag or container) then
− tag = 'kbd'
− end
− if not (tag or container) then +
− tag = 'code'+
− end +
− if not sep then
− sep = '→ '
− end
− if not comment_sep then
− comment_sep = ' '
− end
− +
− after = '<small>' .. after .. '</small>' +
− +
− end
− if not after then
− after = ''
− +
− if tag then +
− nwt = mw.html.create(tag):tag(tag) -- "no-wiki tag", внутри него шаблон не вызывается+
− if nobr then+
− nwt:css('white-space', 'nowrap')+
− end+
+
+
+
− +
Строка 150:
Строка 106:
+
+
+
+
+
− +
− local currentTitle = mw.title.getCurrentTitle().rootText
− if not ucFirst and
− ((ru:uc(currentTitle) ~= currentTitle and -- названия со всеми заглавными буквами
− not mw.ustring.match(currentTitle, '^[А-Яа-яA-Za-z]+:?[А-ЯA-Z]') -- Книга:Литературное наследство, TranslateDate
− ) or
− #currentTitle == 1
− )
− then
− tname = ru:lcfirst(currentTitle)
− else
− tname = currentTitle
− end
−
− -- Имя вызываемого шаблона в неименованном первом параметре (или же взято из названия страницы или
− -- из именованного параметра в отсутствие неименованных — в следующей строчке вреда нет в любом случае),
− -- больше его обрабатывать не надо
− if args._template == nil then
− table.remove(args,1)
− end
− if link then
− content = content .. '[[Шаблон:' .. tname .. '|' .. tname .. ']]'
− else
− content = content .. tname
− end
− content = content .. endl
+
Строка 191:
Строка 128:
− content = content .. (spaced and ' ' or '') .. '|' .. nowiki(param) .. '=' .. nowiki(value) .. endl
− content = content .. (spaced and ' ' or '') .. '|' .. nowiki(v) .. endl
− content = content .. (spaced and ' ' or '') .. '|' .. nowiki(k) .. '=' .. nowiki(v) .. endl
− end
− if spaced then
− content = content .. ' '
− end
− content = content .. '}}' .. nowiki(postfix)
− if container then
− local container_args = {}
− container_args[1] = content
− nwt = expand(frame, container, container_args)
− else
− nwt:wikitext(content):done()
Строка 219:
Строка 142:
− +
вывод кода шаблона через модуль Template call code (функция nowiki() перенесена туда); - параметры |_container= (не используется, функционально покрывается параметром |_tag=) и |_endl= (не используется, отсутствует в документации, область применения не ясна); |_comment= и |_after= разделены (after по аналогии с before — просто текст в конце, не обязательно комментарий)
local p = {}
local p = {}
-- вызов шаблона, при ошибке возвращает пустую строку
-- вызов шаблона, при ошибке возвращает пустую строку
end
end
--return frame:expandTemplate({title = tname, args = args})
--return frame:expandTemplate({title = tname, args = args})
end
end
return str
return str
end
end
function p.main(frame)
function p.main(frame)
local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')
local yesno = require('Module:Yesno')
local args = copy(getArgs(frame, {trim = false, removeBlanks = false})) --copy(frame.args)
local template_code = require('Module:Template call code')._main
local copy = require('Module:TableTools').shallowClone
local args = copy(getArgs(frame, {trim = false, removeBlanks = false}))
local tag = args._tag
local tag = args._tag
local sep = args._sep and args._sep .. ' '
local sep = args._sep and args._sep .. ' '
local prefix = args._prefix or args['_pre-text'] or ''
local prefix = args._prefix or args['_pre-text'] or ''
local postfix = args._postfix or args['_post-text'] or ''
local postfix = args._postfix or args['_post-text'] or ''
local nocat = yesno(args._nocat, false)
local nocat = yesno(args._nocat, false)
local style = args._style
local style = args._style
-- передаётся шаблоном {{стопка примеров}}, один разделитель на все примеры
-- передаётся шаблоном {{стопка примеров}}, один разделитель на все примеры
local comment_sep = args._comment_sep
local comment_sep = args._comment_sep
local comment = args._comment
-- полезно в шаблоне {{стопка примеров}} (это просто текст в конце)
-- полезно в шаблоне {{стопка примеров}} (это просто текст в конце)
local after = args._after or args._comment
local after = args._after or ''
-- полезно в шаблоне {{стопка примеров}} (это просто текст в начале)
-- полезно в шаблоне {{стопка примеров}} (это просто текст в начале)
local before = args._before and args._before .. ' ' or ''
local before = args._before and args._before .. ' ' or ''
if style == 'pre' then
local arrow = expand(frame, 'sp↓', {'', '-0.5em'})
if style == 'pre' or style == '*pre' or style == 'pre↓' or style == '*pre↓' then
tag = tag or 'pre'
end
if style == 'pre' or style == '*pre' then
sep = sep or '\n'
sep = sep or '\n'
elseif style == '*pre' then
elseif style == 'pre↓' or style == '*pre↓' then
sep = sep or arrow
end
sep = sep or '\n'
if style == '*pre' or style == '*pre↓' then
before = '<ul><li>' .. expand(frame, 'chrome bullet hack', {}) .. before
after = after .. '</li></ul>'
end
if style == 'wikitable' then
tag = tag or 'kbd'
sep = sep or '\n| '
sep = sep or '\n| '
comment_sep = '\n| '
comment_sep = '\n| '
end
end
tag = tag or 'code'
sep = sep or '→ '
comment_sep = comment_sep or ' '
if (after) then
if comment then
if not style then
if not style then
comment = '<small>' .. comment .. '</small>'
end
end
after = comment_sep .. after
after = comment_sep .. comment .. after
end
end
local nwt
local _args = copy(args)
_args._style = args._codestyle
_args._comment = args._codecomment
_args._tag = tag
_args._prefix = prefix
_args._postfix = postfix
_args._nowiki = true
if args._template then
table.insert(_args, 1, args._template)
end
end
local content = nowiki(prefix) .. '{{' -- для накопления содержимого тэга
local nwt = template_code(_args, {withoutParams = false})
local tname = args._template or args[1]
local tname = args._template or args[1]
args[k] = nil --больше этот параметр нам не пригодится
args[k] = nil --больше этот параметр нам не пригодится
end
end
elseif not args._template then
-- Имя вызываемого шаблона в неименованном первом параметре (или же взято из названия страницы или
-- из именованного параметра в отсутствие неименованных — в следующей строчке вреда нет в любом случае),
-- больше его обрабатывать не надо
table.remove(args, 1)
end
end
if tname == '' or tname == nil then -- при опущенном первом параметре берём имя шаблона из названия страницы
if tname == '' or tname == nil then -- при опущенном первом параметре берём имя шаблона из названия страницы
local ru = mw.language.new('ru')
local tname = mw.title.getCurrentTitle().rootText
end
end
local targs, equals_pos, param, value, left_shift = {}, 0, '', '', 0
local targs, equals_pos, param, value, left_shift = {}, 0, '', '', 0
for k, v in pairs(args) do
for k, v in pairs(args) do
if type(k) == 'number' then -- неименованные параметры
if type(k) == 'number' then -- неименованные параметры
value = v:sub(equals_pos+1)
value = v:sub(equals_pos+1)
targs[param] = process_nowiki_equals(value)
targs[param] = process_nowiki_equals(value)
left_shift = left_shift + 1 -- переменная нужна, чтобы квазинумерованные параметры, переданные через "{{=}}",
left_shift = left_shift + 1 -- переменная нужна, чтобы квазинумерованные параметры, переданные через "{{=}}",
-- не сбивали порядок
-- не сбивали порядок
else -- истинно неименованные
else -- истинно неименованные
targs[k - left_shift] = process_nowiki_equals(v)
targs[k - left_shift] = process_nowiki_equals(v)
end
end
elseif not k:find('^_') then -- именованные параметры, исключая модификаторы внешнего вида
elseif not k:find('^_') then -- именованные параметры, исключая модификаторы внешнего вида
targs[k] = process_nowiki_equals(v)
targs[k] = process_nowiki_equals(v)
end
end
end
end
end
end
expand_result = tostring(expand(frame, tname, targs))
local expand_result = tostring(expand(frame, tname, targs))
if expand_result:sub(1, 2) == '{|' then
if expand_result:sub(1, 2) == '{|' then
sep = sep .. '\n'
sep = sep .. '\n'