Modul:Custom rule
Documentația acestui modul poate fi creată la Modul:Custom rule/doc
require('strict')
local p = {} --p vine de la pachet
local getArgs = require('Modul:Arguments').getArgs
local yesno = require('Modul:Yesno')
local error_message = require('Modul:Error')['error']
local segment_shortcuts = mw.loadData('Modul:Custom rule/segments')
local function custom_rule_segment(args)
local name
if args[1] then
name = segment_shortcuts[args[1]] or args[1]
end
local size = args[2]
if not name or not size then
return error_message({'[[Modul:Custom rule]] eroare: nu a putut fi interpretat segmentul de separator'})
end
return '[[Fișier:Rule Segment - ' .. name .. ' - ' .. size .. 'px.svg|middle|link=|alt=]]'
end
function p._custom_rule(args)
local rule
if yesno(args.inline or false) then
rule = mw.html.create('span')
else
rule = mw.html.create('div')
end
rule:addClass('wst-custom-rule ' .. (args.class or ''))
if args.style then
rule:attr('style', args.style)
end
local segments = {}
for k, v in pairs(args) do
local i = tonumber(k)
if i and i % 2 == 1 then
table.insert(segments, custom_rule_segment({args[i], args[i + 1]}))
end
end
rule:wikitext(table.concat(segments))
return tostring(rule)
end
function p.custom_rule(frame)
local args = getArgs(frame)
return p._custom_rule(args)
end
return p