Редактирование: Модуль:ExampleList

Перейти к навигации Перейти к поиску

Примечание. Ваши правки будут показаны в статье только после их проверки участником с соответствующими правами.

Правка может быть отменена. Проверьте сравнение версий ниже и нажмите «Записать страницу».
Если отменяемые вами изменения не вандализм, пожалуйста, допишите причину в описании правки.

Текущая версия Ваш текст
Строка 4: Строка 4:
local function copy(other)
local function copy(other)
local res = {}
local res = {}
for k, v in pairs(other) do
for k,v in pairs(other) do
res[k] = v
res[k] = v
end
end
Строка 30: Строка 30:
end
end
yesno = require('Module:Yesno')
yesno = require('Module:Yesno')
local trim = not (yesno(frame:getParent().args.trim or frame:getParent().args._trim, false) == false) -- по умолчанию true
local trim = not (yesno(frame:getParent().args.trim or frame:getParent().args._trim, false) == false) -- по умолчанию true
local args = copy(getArgs(frame, {trim = false, removeBlanks = false})) -- copy(frame.args)
local args = copy(getArgs(frame, {trim = trim, removeBlanks = false})) --copy(frame.args)
for k, v in pairs(args) do
if type(k) == 'number' then
v = v
:gsub('^ *\n+', '')
:gsub('\n+ *$', '')
if trim then
v = v
:gsub('^ +', '')
:gsub(' +$', '')
end
args[k] = v
end
end
local tname = args.t or args._t or args.template or args._template
local tname = args.t or args._t or args.template or args._template
local ucFirst = yesno(args.u or args._u, false)
local opener = args.opener or args._opener
local opener = args.opener or args._opener
local sep = args.sep or args._sep
local sep = args.sep or args._sep
Строка 66: Строка 51:
opener = ''
opener = ''
if between == nil and (style == '*pre' or style == '*pre↓') then
if between == nil and (style == '*pre' or style == '*pre↓') then
if mw.isSubsting() then
between = '<div style="margin-top:3em"></div>' -- содержимое шаблона {{^|3em}}
between = '{{^|3em}}'
else
between = '<div style="margin-top:3em"></div>'
end
end
end
else
else
Строка 77: Строка 58:
end
end
if between == nil and (style == 'pre' or style == '*pre' or style == 'pre↓' or style == '*pre↓') then
if between == nil and (style == 'pre' or style == '*pre' or style == 'pre↓' or style == '*pre↓') then
if mw.isSubsting() then
between = '<div style="margin-top:2em"></div>' -- содержимое шаблона {{^|2em}}
between = '{{^|2em}}'
else
between = '<div style="margin-top:2em"></div>'
end
end
end
if tname == '' or tname == nil then -- при опущенном первом параметре берём имя шаблона из названия страницы
if tname == '' or tname == nil then -- при отсутствующем имени шаблона берём его из названия страницы
local ru = mw.language.new('ru')
tname = mw.language.new('ru'):lcfirst(mw.title.getCurrentTitle().rootText)
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
end
end
-- Узнаем, заполнено ли где-то поле комментария
local content, are_comments, i = '', false, 0
local are_comments = false
for k, v in pairs(args) do
local pre_targs = {}
if type(k) == 'number' then
if v ~= '' then
pre_targs = mw.text.split(v, '\\')
for k2, v2 in pairs(pre_targs) do
local equals_pos
if v2:sub(1, 1) == '_' and v2:find('=') then  -- параметры настроек шаблона {{пример}}
equals_pos = v2:find('=')
end
if equals_pos then
local param = v2:sub(1, equals_pos - 1)
if param == '_comment' then are_comments = true end
end
end
end
end
end
local content, i = '', 0
for k, v in pairs(args) do
for k, v in pairs(args) do
local pre_targs, targs = {}, {}
local pre_targs, targs = {}, {}
Строка 127: Строка 71:
i = i + 1
i = i + 1
if are_comments then
targs._comment = ''  -- значение по умолчанию
end
if v ~= '' then
if v ~= '' then
pre_targs = mw.text.split(v, '\\')
pre_targs = mw.text.split(v, '\\')
for k2, v2 in pairs(pre_targs) do
for k2, v2 in pairs(pre_targs) do
local equals_pos
equals_pos = nil
if v2:sub(1, 1) == '_' and v2:find('=') then -- параметры настроек шаблона {{пример}}
if v2:sub(1, 1) == '_' and v2:find('=') then -- параметры настроек шаблона "пример"
equals_pos = v2:find('=')
equals_pos = v2:find('=')
end
end
if equals_pos then
if equals_pos then
local param = v2:sub(1, equals_pos - 1)
param = v2:sub(1, equals_pos-1)
local value = v2:sub(equals_pos + 1)
value = v2:sub(equals_pos+1)
targs[param] = value
targs[param] = value
if param == '_comment' then are_comments = true end
else
else
if v2:sub(1, 5) == '&#95;' then
if v2:sub(1, 5) == '&#95;' then
Строка 152: Строка 94:
table.insert(targs, 1, tname)
table.insert(targs, 1, tname)
targs._sep, targs._style, targs._nobr, targs._nocat, targs._spaced, targs._comment_sep = sep, style, nobr,
targs._sep, targs._style, targs._nobr, targs._nocat, targs._spaced, targs._comment_sep, targs._prefix, targs._postfix
nocat, spaced, comment_sep
= sep, style, nobr, nocat, spaced, comment_sep, prefix, postfix
if not targs._prefix then
targs._prefix = prefix
end
if not targs._postfix then
targs._postfix = postfix
end
local adjusted_opener
local adjusted_opener
if style == 'pre' and opener == '*' and targs._before == nil then
if style == 'pre' and opener == '*' and targs._before == nil then
Строка 165: Строка 101:
targs._style = '*pre'
targs._style = '*pre'
else
else
if style == 'pre' and opener == '*' then
adjusted_opener = opener
if mw.isSubsting() then
targs._before = targs._before .. '{{^|-0.5em}}'
else
targs._before = targs._before .. '<div style="margin-top:-0.5em"></div>'
end
end
adjusted_opener = opener == '*' and '* ' or opener
end
end
--[[if not targs._style then
--[[if not targs._style then
Строка 178: Строка 107:
end]]
end]]
local exampleCode
content = content .. (i ~= 1 and (between and between .. '\n' or '\n') or '') .. adjusted_opener .. tostring(expand(frame, 'пример', targs))
if mw.isSubsting() then
exampleCode = '{{пример'
for name, value in pairs(targs) do
if type(name) == 'number' then
exampleCode = exampleCode .. '|' .. value
else
exampleCode = exampleCode .. '|' .. name .. '=' .. value
end
end
exampleCode = exampleCode .. '}}'
else
exampleCode = tostring(expand(frame, 'пример', targs))
end
content = content .. (i ~= 1 and (between and between .. '\n' or '\n') or '') .. adjusted_opener .. exampleCode
end
end
end
end

Быстрая вставка: «» „“ | {{}} [[]] [] [[|]] {{|}} {{подст:}} <br> &nbsp; #перенаправление [[]] [[Категория:]] {{DEFAULTSORT:}} [[Участник:]] {{u|}} {{userlinks|}} {{ping|}} {{pagelinks|}} {{D-|}} [[d:|]] ~~~~

__NOTOC__ __TOC__ __FORCETOC__   [[ ()|]] [[ (фильм)|]] {{commonscat|}} [[wikt:]] [[Special:Diff/|]] [[Special:Permalink/|]] [[Special:Contributions/]]

Теги: <></>   <!-- -->   <blockquote></blockquote>   <code></code>   <code><nowiki></nowiki></code>   <nowiki></nowiki>   <includeonly></includeonly>   <noinclude></noinclude>   <onlyinclude></onlyinclude>   <poem></poem>   <pre></pre>   <s></s>   <small></small>   <syntaxhighlight lang=""></syntaxhighlight>   <sub></sub>   <sup></sup>

Теги галереи файлов: <gallery></gallery>   <gallery class="center" caption=""></gallery>   <gallery mode="packed" heights="" caption=""></gallery>

Разделы: == ==   === ===   == См. также ==   == Примечания == {{примечания}}   == Литература ==   == Ссылки ==

Шаблоны: {{tl|}}   {{cl|}}   {{clear}}   {{lang-en|}}   {{ref-en}}   {{s|}}   {{неоднозначность}}   {{колонки}}{{колонки|конец}}   {{подст:L}}   {{начало цитаты}}{{конец цитаты|источник=}}   {{hello}}~~~~  

Источники: <ref></ref>   <ref name=""></ref>   <ref name="" />   <ref group=""></ref>   {{ref+||group=""}}  

Символы: Ё ё ~ # @ § · ¡ ¿ \ ½ ¼ ¾ ± × ÷ ° ^ ¹ ² ³ £ ¥ $ ¢ © ® {{подст:ударение}}

Греческий алфавит: Α α Β β Γ γ Δ δ Ε ε Ζ ζ Η η Θ θ Ι Ϊ ι ϊ Κ κ Λ λ Μ μ Ν ν Ξ ξ Ο ο Π π Ρ ρ Σ σ ς Τ τ Υ Ϋ υ ϋ Φ φ Χ χ Ψ ψ Ω ω