Шаблон:Карточка/строка: различия между версиями

Материал из Энциклопедия автомобильных номеров мира
Перейти к навигации Перейти к поиску
(Новая страница: «Test»)
м (Новая страница: «Test»)
Строка 1: Строка 1:
{{#if:{{{hidden|}}}|[[Категория:{{#ifeq:{{NAMESPACENUMBER}}|10|Шаблоны|ЭАНМ}}:Незавершённый перевод с {{#ifeq:{{translate/Язык|{{{1}}}}}|иностранн|неизвестного языка|{{translate/Язык|{{{1}}}}}ого}}]]<!-- если текст скрыт, то нет смысла не категоризовать -->|
local p = {}
{{ambox
 
|type=content
-- используется для того, чтобы можно было удалять элементы из таблицы
|text='''{{#switch:{{NAMESPACE}}|{{ns:10}}=Этот шаблон|{{ns:0}}=Эта статья или раздел|#default=Эта страница}} содержит незавершённый перевод с <!--  
local function copy(other)
-->{{#if:{{{1}}}<!-- если язык задан -->
local res = {}
  |<!-- Анализируем выдачу подшаблона и в зависимости от результата либо викифицируем, либо оставляем невикифицированное «иностранного языка» -->{{#ifeq:{{translate/Язык|{{{1}}}}}|иностранн|иностранного языка|[[{{translate/Язык|{{{1}}}}}ий язык|{{translate/Язык|{{{1}}}}}ого языка]]}}.<includeonly>{{#if:{{{nocat|}}}||[[Категория:<!--
for k,v in pairs(other) do
  -->{{#ifeq:{{NAMESPACENUMBER}}|10|Шаблоны|ЭАНМ}}:<!--  
res[k] = v
-->Незавершённый перевод с {{#ifeq:{{translate/Язык|{{{1}}}}}|иностранн|неизвестного языка|{{translate/Язык|{{{1}}}}}ого}}]]}}</includeonly>
end
  |иностранного языка.<includeonly>{{#if:{{{nocat|}}}||[[Категория:ЭАНМ:Страницы с некорректным использованием шаблонов:Перевести]]}}</includeonly><!-- если язык не задан, передана пустая строка
return res
-->}}'''<!-- if -->
end
|text-small=Вы можете помочь проекту, закончив перевод. {{#if:{{{1|}}}||Если вы знаете, на каком языке написан фрагмент, укажите его в этом шаблоне.}}}}<!--
 
-->}}<includeonly>{{#if:{{{nocat|}}}||{{#ifeq:{{NAMESPACE}}|{{ns:10}}|[[Категория:ЭАНМ:Заимствованные шаблоны]]}}}}</includeonly><noinclude>
-- вызов шаблона, при ошибке возвращает пустую строку
{{doc}}
local function expand(frame, tname, targs)
</noinclude>
local success, result = pcall(
frame.expandTemplate,
frame,
{title = tname, args = targs}
)
if success then
return result
else
return ''
end
--return frame:expandTemplate({title = tname, args = args})
end
 
function p.main(frame)
if not getArgs then
getArgs = require('Module:Arguments').getArgs
end
yesno = require('Module:Yesno')
local trim = not (yesno(frame:getParent().args.trim or frame:getParent().args._trim, false) == false) --по умолчанию true
local args = copy(getArgs(frame, {trim = trim, removeBlanks = false})) --copy(frame.args)
local tname = args.t or args._t or args.template or args._template
local opener = args.opener or args._opener or '* '
local sep = args.sep or args._sep
local style = args.style or args._style
local nobr = args.nobr or args._nobr
local nocat = args.nocat or args._nocat
local spaced = args.spaced or args._spaced
local comment_sep = args.comment_sep or args._comment_sep
local inthemiddle = yesno(args.inthemiddle or args._inthemiddle, false)
local wide = yesno(args.wide or args._wide, false)
if not (args.opener or args._opener) then
if style == 'wikitable' then
opener = '|-\n| '
elseif style == 'pre' or style == '*pre' or style == 'pre↓' or style == '*pre↓' then
opener = ''
end
end
if tname == '' or tname == nil then --при опущенном первом параметре берём имя шаблона из названия страницы
tname = mw.language.new('ru'):lcfirst(mw.title.getCurrentTitle().rootText)
end
local content, are_comments = '', false
for k, v in pairs(args) do
local pre_targs, targs = {}, {}
if type(k) == 'number' then
if v ~= '' then
pre_targs = mw.text.split(v, '\\')
for k2, v2 in pairs(pre_targs) do
equals_pos = nil
if v2:sub(1, 1) == '_' and v2:find('=') then --параметры настроек шаблона "пример"
equals_pos = v2:find('=')
end
if equals_pos then
param = v2:sub(1, equals_pos-1)
value = v2:sub(equals_pos+1)
targs[param] = value
if param == '_comment' then are_comments = true end
else
if v2:sub(1, 5) == '&#95;' then
targs[k2] = v2:gsub('&#95;', '_')
else
targs[k2] = v2
end
end
end
end
table.insert(targs, 1, tname)
targs._sep, targs._style, targs._nobr, targs._nocat, targs._spaced, targs._comment_sep
= sep, style, nobr, nocat, spaced, comment_sep
content = content .. opener .. tostring(expand(frame, 'пример', targs)) .. '\n'
end
end
if style == 'wikitable' then
local table_content = ''
if not inthemiddle then
table_content = '{| class="wikitable '
if wide then table_content = table_content .. 'wide' end
table_content = table_content .. '"\n! Код !! Результат'
if are_comments then table_content = table_content .. ' !! Комментарий' end
end
content = table_content .. '\n' .. content
if not inthemiddle then
content = content .. '|}'
else
content = content:sub(1, -2)
end
else
content = content:sub(1, -2)
end
return content
end
 
return p

Версия от 00:45, 17 марта 2015

local p = {}

-- используется для того, чтобы можно было удалять элементы из таблицы local function copy(other) local res = {} for k,v in pairs(other) do res[k] = v end return res end

-- вызов шаблона, при ошибке возвращает пустую строку local function expand(frame, tname, targs) local success, result = pcall( frame.expandTemplate, frame, {title = tname, args = targs} ) if success then return result else return end --return frame:expandTemplate({title = tname, args = args}) end

function p.main(frame) if not getArgs then getArgs = require('Module:Arguments').getArgs end yesno = require('Module:Yesno') local trim = not (yesno(frame:getParent().args.trim or frame:getParent().args._trim, false) == false) --по умолчанию true local args = copy(getArgs(frame, {trim = trim, removeBlanks = false})) --copy(frame.args) local tname = args.t or args._t or args.template or args._template local opener = args.opener or args._opener or '* ' local sep = args.sep or args._sep local style = args.style or args._style local nobr = args.nobr or args._nobr local nocat = args.nocat or args._nocat local spaced = args.spaced or args._spaced local comment_sep = args.comment_sep or args._comment_sep local inthemiddle = yesno(args.inthemiddle or args._inthemiddle, false) local wide = yesno(args.wide or args._wide, false) if not (args.opener or args._opener) then if style == 'wikitable' then opener = '|-\n| ' elseif style == 'pre' or style == '*pre' or style == 'pre↓' or style == '*pre↓' then opener = end end

if tname == or tname == nil then --при опущенном первом параметре берём имя шаблона из названия страницы tname = mw.language.new('ru'):lcfirst(mw.title.getCurrentTitle().rootText) end

local content, are_comments = , false for k, v in pairs(args) do local pre_targs, targs = {}, {} if type(k) == 'number' then if v ~= then pre_targs = mw.text.split(v, '\\') for k2, v2 in pairs(pre_targs) do equals_pos = nil if v2:sub(1, 1) == '_' and v2:find('=') then --параметры настроек шаблона "пример" equals_pos = v2:find('=') end if equals_pos then param = v2:sub(1, equals_pos-1) value = v2:sub(equals_pos+1) targs[param] = value if param == '_comment' then are_comments = true end else if v2:sub(1, 5) == '_' then targs[k2] = v2:gsub('_', '_') else targs[k2] = v2 end end end end table.insert(targs, 1, tname) targs._sep, targs._style, targs._nobr, targs._nocat, targs._spaced, targs._comment_sep = sep, style, nobr, nocat, spaced, comment_sep content = content .. opener .. tostring(expand(frame, 'пример', targs)) .. '\n' end end if style == 'wikitable' then local table_content = if not inthemiddle then table_content = '{| class="wikitable ' if wide then table_content = table_content .. 'wide' end table_content = table_content .. '"\n! Код !! Результат' if are_comments then table_content = table_content .. ' !! Комментарий' end end content = table_content .. '\n' .. content if not inthemiddle then content = content .. '|}' else content = content:sub(1, -2) end else content = content:sub(1, -2) end

return content end

return p