Jump to content
Wikipedia The Free Encyclopedia

Module:Infobox rune/sandbox

From Wikipedia, the free encyclopedia
This is the module sandbox page for Module:Infobox rune (diff).
Module documentation[view] [edit] [history] [purge]

Implements {{Infobox rune }}

The above documentation is transcluded from Module:Infobox rune/doc. (edit | history)
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Add categories to the /doc subpage. Subpages of this module.
 --
 -- This module implements {{Infobox rune}}
 --
 require('strict')

 localp={}

 localgetArgs=require('Module:Arguments').getArgs

 localfunctionaddCells(row,entries,subcols,fs)
 iftype(entries)=='string'then
 localcolspan=subcols[1]+subcols[2]+subcols[3]
 row:tag('td')
 :css('font-size',fs)
 :css('padding','1px')
 :attr('colspan',colspan)
 :wikitext(entries)
 else
 fork=1,3do
 ifsubcols[k]>0then
 ifentries[k]andtype(entries[k])=='string'then
 ifentries[k]~='<same>'then
 localcolspan=subcols[k]
 forj=(k+1),3do
 ifentries[j]andentries[j]=='<same>'then
 colspan=colspan+subcols[j]
 else
 break
 end
 end
 row:tag('td')
 :css('font-size',fs)
 :css('padding','1px')
 :attr('colspan',(colspan>1)andcolspanornil)
 :wikitext(entries[k])
 end
 elseifentries[k]then
 forj=1,subcols[k]do
 ifentries[k][j]then
 row:tag('td')
 :css('font-size',fs)
 :css('padding','1px')
 :wikitext(entries[k][j])
 else
 row:tag('td')
 end
 end
 else
 forj=1,subcols[k]do
 row:tag('td')
 end
 end
 end
 end
 end
 end

 functionp.infobox(frame)
 localargs=getArgs(frame)

 locallanglinks={
 pg='[[Proto-Germanic language|Proto-Germanic]]',
 oe='[[Old English]]',
 on='[[Old Norse]]'
 }

 localshapelinks={
 pg='[[Elder Futhark]]',
 oe='[[Anglo-Saxon runes|Futhorc]]',
 on='[[Younger Futhark]]'
 }

 locallet2num={
 a='1',
 b='2',
 c='3',
 d='4',
 e='5'
 }

 -- fill in the entries
 localentrynames={'lang','name','meaning','shape','unicode hex',
 'transliteration','transcription','IPA','position'}
 localentries={}
 fori=1,#entrynamesdo
 entries[entrynames[i]]=nil
 end

 fork,vinpairs(args)do
 k=''..k
 localpre,num,num2,let=nil,nil,nil,nil
 fori=1,#entrynamesdo
 pre,num,let=k:match('^('..entrynames[i]..')([1-3])([a-e]?)$')
 num2=nil
 ifprethenbreakend
 pre,num,num2=k:match('^('..entrynames[i]..')([1-3])([1-3]?)$')
 let=nil
 ifprethenbreakend
 end
 ifpre=='unicode hex'then
 v='&#x'..v..'; '..'<div style="font-size: 30%">U+'..v..'</div>'
 end
 ifnumandnum~=''then
 num=tonumber(num)
 ifletandlet~=''then
 ifentries[pre]andtype(entries[pre])=='table'then
 ifentries[pre][num]andtype(entries[pre][num])=='table'then
 entries[pre][num][tonumber(let2num[let])]=v
 else
 entries[pre][num]={nil,nil,nil,nil,nil}
 entries[pre][num][tonumber(let2num[let])]=v
 end
 else
 entries[pre]={nil,nil,nil}
 entries[pre][num]={nil,nil,nil,nil,nil}
 entries[pre][num][tonumber(let2num[let])]=v
 end
 elseifnum2andnum2~=''then
 num2=tonumber(num2)
 ifentries[pre]andtype(entries[pre])=='table'then
 entries[pre][num]=v
 fori=(num+1),num2do
 entries[pre][i]='<same>'
 end
 else
 entries[pre]={nil,nil,nil}
 entries[pre][num]=v
 fori=(num+1),num2do
 entries[pre][i]='<same>'
 end
 end
 else
 ifentries[pre]andtype(entries[pre])=='table'then
 entries[pre][num]=v
 else
 entries[pre]={nil,nil,nil}
 entries[pre][num]=v
 end
 end
 elseifprethen
 entries[pre]=v
 end
 end

 localsubcols={0,0,0}

 -- determine the number of subcolumns per column
 fori=1,#entrynamesdo
 locale=entries[entrynames[i]]
 ifethen
 iftype(e)=='table'then
 forj=1,3do
 ife[j]andtype(e[j])=='table'then
 localn=#(e[j])
 ifn>subcols[j]then
 subcols[j]=n
 end
 elseife[j]then
 if1>subcols[j]then
 subcols[j]=1
 end
 end
 end
 end
 end
 end

 locallets={'a','b','c','d','e'}

 -- build the table
 localroot=mw.html.create()

 root=root
 :tag('table')
 :addClass('wikitable')
 :addClass('plainrowheaders')
 :css('float',args.floator'right')
 :css('clear',(args.float=='none'and'both')orargs.floator'right')
 :css('width',args.widthor'auto')
 :css('margin',args.float=='left'and'0.5em 1.0em 0.5em 0'or'0.5em 0 0.5em 1.0em')
 :css('font-size','88%')
 :css('text-align','center')

 localrowspan=1+(entries['name']and1or0)+(entries['meaning']and1or0)
 -- Name
 localrow=root:tag('tr')
 row:tag('th')
 :attr('scope','row')
 :attr('rowspan',(rowspan>1)androwspanornil)
 :css('vertical-align','middle')
 :wikitext('Name')
 fork=1,3do
 ifsubcols[k]>0then
 localv=langlinks[(args['lang'..k]or''):lower()]orargs['lang'..k]
 row:tag('th')
 :attr('scope','col')
 :attr('colspan',(subcols[k]>1)andsubcols[k]ornil)
 :wikitext(v)
 end
 end
 ifentries['name']then
 row=root:tag('tr'):css('font-size','150%')
 addCells(row,entries['name'],subcols,nil)
 end
 ifentries['meaning']then
 row=root:tag('tr')
 addCells(row,entries['meaning'],subcols,nil)
 end
 ifentries['shape']then
 row=root:tag('tr')
 row:tag('th')
 :attr('scope','row')
 :attr('rowspan',2)
 :css('vertical-align','middle')
 :wikitext('Shape')
 fork=1,3do
 ifsubcols[k]>0then
 localv=shapelinks[(args['lang'..k]or''):lower()]or''
 row:tag('th')
 :attr('scope','col')
 :attr('colspan',(subcols[k]>1)andsubcols[k]ornil)
 :wikitext(v)
 end
 end
 row=root:tag('tr')
 addCells(row,entries['shape'],subcols,nil)
 end
 ifentries['unicode hex']then
 row=root:tag('tr')
 row:tag('th')
 :attr('scope','row')
 :css('vertical-align','middle')
 :wikitext('[[Runic (Unicode block)|Unicode]]')
 addCells(row,entries['unicode hex'],subcols,'300%')
 end
 ifentries['transliteration']then
 row=root:tag('tr')
 row:tag('th')
 :attr('scope','row')
 :css('vertical-align','middle')
 :wikitext('[[Runic transliteration and transcription|Transliteration]]')
 addCells(row,entries['transliteration'],subcols,'120%')
 end
 ifentries['transcription']then
 row=root:tag('tr')
 row:tag('th')
 :attr('scope','row')
 :css('vertical-align','middle')
 :wikitext(entries['transliteration']and'Transcription'
 or'[[Runic transliteration and transcription|Transcription]]')
 addCells(row,entries['transcription'],subcols,'120%')
 end
 ifentries['IPA']then
 row=root:tag('tr')
 row:tag('th')
 :attr('scope','row')
 :css('vertical-align','middle')
 :wikitext('[[International Phonetic Alphabet|IPA]]')
 addCells(row,entries['IPA'],subcols,'150%')
 end
 ifentries['position']then
 row=root:tag('tr')
 row:tag('th')
 :attr('scope','row')
 :css('vertical-align','middle')
 :wikitext('Position in rune-row')
 addCells(row,entries['position'],subcols,nil)
 end

 returntostring(root)
 end

 returnp

AltStyle によって変換されたページ (->オリジナル) /