Модуль:Клавиатура компьютераЭто модуль для шаблона {{Клавиатура компьютера}} local p = {}
local function getLayout(frame)
local pframe = frame:getParent()
local layoutPage = pframe.args[1]
local layout = pframe.args['раскладка']
if layout == nil or layout == '' then
if layoutPage == nil or layoutPage == '' then
layoutPage='PC ISO'
elseif layoutPage=='Apple' or layoutPage=='apple' then
layoutPage='Apple ISO'
end
local layoutSubpage = mw.title.new('Клавиатура компьютера/'..layoutPage,'шаблон')
if layoutSubpage==nil then
error('не найдена страница '..'Шаблон:Клавиатура компьютера/' .. layoutPage)
end
layout=layoutSubpage:getContent()
end
local labelsPage = pframe.args[2]
local labels = pframe.args['обозначения']
if layoutPage ~= nil and layoutPage ~=''
and (labels ==nil or labels == '') then
if labelsPage == nil or labelsPage == '' then
labelsPage = 'RU'
end
local labelsSubpage=mw.title.new('Клавиатура компьютера/'..layoutPage..'/'..labelsPage..'.json','шаблон')
if labelsSubpage==nil then
error('не найден пакет обозначений '..labelsPage)
end
labels = labelsSubpage:getContent()
end
local labelsArr = mw.text.jsonDecode(labels)
return {layout,labelsArr}
end
function p.draw(frame)
local gl=getLayout(frame)
local layout=gl[1]
local labelsArr=gl[2]
local keyPage='Клавиатура компьютера/Клавиша'
local pframe = frame:getParent()
if pframe.args['тип клавиши']=='круглая' then
keyPage='Клавиатура компьютера/Круглая клавиша'
end
local result = ''
local x=0;
local y=0;
local nrow = 1;
local ncol = 1;
for row in mw.text.gsplit(layout,'\n',true) do
if row=='--' then break end
for itm in mw.text.gsplit(row,';',true) do
local keyCaption=''
local keyLink=''
local curLabel = labelsArr[nrow][ncol]
if type(curLabel)=='table' then
keyCaption=curLabel['c']
keyLink=curLabel['l']
else
keyCaption=curLabel or ''
end
keyCaption=frame:preprocess(keyCaption)
keyCaption=string.gsub(keyCaption,'\n','<br>')
local width=string.match(itm,'[0-9.]+')
local height=1
if string.sub(itm,1,1)=='R' then
y=y-1+width
nrow=nrow-1
break
end
if string.sub(itm,1,1)=='V' then
height=width
width=1
end
if itm=='ISOENTER' then
width=1
result=result..frame:expandTemplate{
title=keyPage,
args={'',(x+0.25)*40,(y+1)*40-4,36,30}
}
result=result..frame:expandTemplate{
title=keyPage,
args={'',x*40,y*40,46}
}
result=result..frame:expandTemplate{
title=keyPage,
args={keyCaption,(x+0.25)*40+2,y*40,36,66,keyLink,
['дополнительный стиль']='border-left:none;border-top-left-radius:0;'}
}
x=x+1.5
ncol=ncol+1
elseif itm=='STEPCAPS' then
result=result..frame:expandTemplate{
title=keyPage,
args={'',x*40,y*40,56}
}
result=result..frame:expandTemplate{
title=keyPage,
args={keyCaption,x*40,y*40,36,26,keyLink}
}
x=x+1.75
ncol=ncol+1
elseif width~=nil then
if string.sub(itm,1,1) ~='S' then
result=result..frame:expandTemplate{
title=keyPage,
args={keyCaption,x*40,y*40,width*40-14,height*40-14,keyLink}
}
ncol=ncol+1
end
x=x+width
end
end
x=0
ncol=1
nrow=nrow+1
y=y+1
end
return '<div style="position:relative">'..result..'</div>'
end
function p.getWidth(frame)
local gl=getLayout(frame)
local layout=gl[1]
maxWidth=0;
for row in mw.text.gsplit(layout,'\n',true) do
local curWidth=0
if row=='--' then break end
for itm in mw.text.gsplit(row,';',true) do
local width=string.match(itm,'[0-9.]+')
if string.sub(itm,1,1)=='V' then
width=1
elseif itm=='ISOENTER' then
width=1.5
elseif itm=='STEPCAPS' then
width=1.75
end
if width~=nil then
curWidth=curWidth+width
end
end
if maxWidth<curWidth then
maxWidth=curWidth
end
end
return (maxWidth*40+5)
end
function p.getHeight(frame)
local gl=getLayout(frame)
local layout=gl[1]
local height=0
for row in mw.text.gsplit(layout,'\n',true) do
local curHeight=1
if string.sub(row,1,1)=='R' then
curHeight=string.match(row,'[0-9.]+')
end
height=height+curHeight
end
return (height*40)
end
return p
|
Index:
pl ar de en es fr it arz nl ja pt ceb sv uk vi war zh ru af ast az bg zh-min-nan bn be ca cs cy da et el eo eu fa gl ko hi hr id he ka la lv lt hu mk ms min no nn ce uz kk ro simple sk sl sr sh fi ta tt th tg azb tr ur zh-yue hy my ace als am an hyw ban bjn map-bms ba be-tarask bcl bpy bar bs br cv nv eml hif fo fy ga gd gu hak ha hsb io ig ilo ia ie os is jv kn ht ku ckb ky mrj lb lij li lmo mai mg ml zh-classical mr xmf mzn cdo mn nap new ne frr oc mhr or as pa pnb ps pms nds crh qu sa sah sco sq scn si sd szl su sw tl shn te bug vec vo wa wuu yi yo diq bat-smg zu lad kbd ang smn ab roa-rup frp arc gn av ay bh bi bo bxr cbk-zam co za dag ary se pdc dv dsb myv ext fur gv gag inh ki glk gan guw xal haw rw kbp pam csb kw km kv koi kg gom ks gcr lo lbe ltg lez nia ln jbo lg mt mi tw mwl mdf mnw nqo fj nah na nds-nl nrm nov om pi pag pap pfl pcd krc kaa ksh rm rue sm sat sc trv stq nso sn cu so srn kab roa-tara tet tpi to chr tum tk tyv udm ug vep fiu-vro vls wo xh zea ty ak bm ch ny ee ff got iu ik kl mad cr pih ami pwn pnt dz rmy rn sg st tn ss ti din chy ts kcg ve
Portal di Ensiklopedia Dunia