وحدة:Abyat
توثيق الوحدة[أنشئ] [محو الاختزان][استخدامات] [قوالب]
local aliases = {
width = {'العرض', 'عرض'},
title = {'عنوان', 'العنوان'},
shaer = {'الشاعر', 'شاعر'},
bahar = {'البحر', 'بحر'},
nass = {1,'النص', 'نص'},
shaterbyshater = {'شطر شطر'},
fasil = {'فاصل','separator','fasil'},
}
local string = mw.ustring
local function argument_wrapper(arg)
local nilargs = {}
return setmetatable({},
{
__index = function ( tbl, k )
local v = rawget(tbl,k)
if v then
return v
elseif nilargs[k] then
return nil
end
local list = (type(k)=="number") and k or aliases[k];
for _,arglist in ipairs(arg) do
if type( list ) == 'table' then
for _, alias_key in ipairs( list ) do
if arglist[alias_key] then
v = arglist[alias_key]
break;
end
end
elseif list ~= nil then
v = arglist[list]
end
if v then
break;
end
end
if v == nil then
nilargs[k] = true
else
rawset( tbl, k, v )
end
return v
end,
});
end
local function validString(s)
if(type(s) == 'string') then
s = mw.text.trim(s)
if( s ~= '' ) then return s end
end
return nil
end
local function abyat(frame)
local A = argument_wrapper({frame:getParent().args, frame.args,mw.loadData("Module:Art pref/data")["أبيات"] or {}})
local mashtoor = false
local header = ''
local fasil = A.fasil and string.gsub(A.fasil, '[%%%^%$%(%)%[%]%.%*%+%-%?]', '%%%1') or "\\\\"
local fasil_s,fasil_e = string.find(mw.text.trim(A.nass),fasil)
local sdrdiv = '<div class="abyat-sdr">'
if not fasil_s and not A[2] then
mashtoor=true
sdrdiv = '<div>'
end
local nass= ""
local ret = '<div class="abyat-wrapper' .. (mashtoor and ' mashtoor' or '') ..
(A.shaterbyshater and ' abyat-shaterbyshater' or '') ..
'" style="width:' .. (A.width or 'fit-content') .. ';">'
if A.title then
header = header .. "<center>'''" .. A.title .. "'''</center>"
end
if A.shaer then
header = header .. "<center>" .. A.shaer .. "</center>"
end
if A.bahar then
header = header .. "<center>''[من " .. A.bahar .. "]''</center>"
end
-- نمط متوافق مع أساليب القوالب القديمة
if A[2] then
local shater_num =1
local aa,bb
aa = validString(A[shater_num])
bb = validString(A[shater_num+1])
while aa ~= nil or bb ~= nil do
if aa~= nil and bb ~= nil then
ret=ret .. '<div class="abyat-sdr">' ..aa .. "</div>"
ret=ret .. '<div class="abyat-ajz">' ..bb .. "</div>\n"
else
ret=ret .. '<div class="abyat-single_bayt">' ..(aa or bb) .. "</div>\n"
end
shater_num=shater_num+2
aa = validString(A[shater_num])
bb = validString(A[shater_num+1])
end
else
-- نمط أبيات
nass = mw.text.trim(A.nass)
if fasil_s == 1 then
ret = ret .. '<div class="abyat-single_bayt">'
nass = string.sub(nass,fasil_e+1)
else
ret = ret .. sdrdiv
end
nass=string.gsub(nass,"\n"..fasil,'</div><div class="abyat-single_bayt">')
nass=string.gsub(nass,"\n([^|])",'</div>' .. sdrdiv ..'%1')
nass=string.gsub(nass, fasil,'</div><div class="abyat-ajz">')
end
return header .. ret .. nass .. "</div></div>"
end
return {abyat=abyat}