Anda dapat membuat halaman dokumentasi untuk buat pada modul Scribunto ini.
Penyunting dapat melakukan uji coba pada halaman bak pasir (buat | cermin) dan kasus uji (buat) modul ini.
Subhalaman modul ini.
Penyunting dapat melakukan uji coba pada halaman bak pasir (buat | cermin) dan kasus uji (buat) modul ini.
Subhalaman modul ini.
-- implements [[template:image array]] localp={} localfunctionisnotempty(s) returnsands:match('^%s*(.-)%s*$')~='' end localfunctioncleanImageName(img) ifnotimgthenreturn''end returnmw.ustring.gsub(img,'^[Ff]ile:',''):gsub('^[Bb]erkas:','') end localfunctionrenderArrayCell(img,c,a,b,l,cl,tc,t,w,h) localalt=isnotempty(a)and('|alt='..a)or'' locallink=isnotempty(l)and('|link='..l)or'' localclass=isnotempty(cl)and('|class='..cl)or'' localtext=(isnotempty(tc)andnotisnotempty(t)) andmw.text.unstrip(c)ormw.text.unstrip(tor'') localborder=isnotempty(b)and'|border'or'' localcell=mw.html.create('') if(img)then cell:tag('div') :css('display','table-cell') :css('vertical-align','middle') :css('width',w..'px') :css('height',h..'px') :css('margin-left','auto') :css('margin-right','auto') :wikitext(mw.ustring.format('[[Berkas:%s|%dx%dpx%s|%s]]', cleanImageName(img),w,h,alt..link..class..border,text)) cell:tag('div') :css('padding','1px') :wikitext(c) end returntostring(cell) end functionp._imagearray(args) localwidth=tonumber(args['width']or'60') localheight=tonumber(args['height']or'70') localperrow=tonumber(args['perrow']or'4') localbw=tonumber(args['border-width']or'0') localfs=args['font-size']or'88%' localtext=args['text']or'' localmargin=args['margin']or'auto' localborder=(bw>0)andtostring(bw)..'px #aaa solid'ornil -- find all the nonempty image numbers localimagenums={} localimagecount=0 fork,vinpairs(args)do locali=tonumber(tostring(k):match('^%s*image([%d]+)%s*$')or'0') if(i>0andisnotempty(v))then table.insert(imagenums,i) imagecount=imagecount+1 end end -- sort the image numbers table.sort(imagenums) -- compute the number of rows localrowcount=math.ceil(imagecount/perrow) ifrowcount<1then return'[[Kategori:Halaman yang menggunakan image array tanpa gambar]]' end -- start table localroot=mw.html.create('table') root :addClass(args['class']) :css('border-collapse','collapse') :css('text-align','center') :css('font-size',fs) :css('line-height','1.25em') :css('margin',margin) :css('width',tostring(width*perrow)..'px') -- loop over the images forj=1,rowcountdo localrow=root:tag('tr') row:css('vertical-align','top') fork=1,perrowdo locali=imagenums[(j-1)*perrow+k]or0 row:tag('td') :css('width',width..'px') :css('text-align','center') :css(borderand'border'or'',borderor'') :wikitext(renderArrayCell( args['image'..i],args['caption'..i],args['alt'..i], args['border'..i],args['link'..i],args['class'..i], args['text'],args['text'..i],width,height) ) end end -- end table returntostring(root) end functionp.array(frame) localargs=frame:getParent().args returnp._imagearray(args) end returnp