Jump to content

Module:Block diagram

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Wnt (talk | contribs) at 18:44, 5 May 2013 (debug and also split all the concats for hypothetical speed). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p={}

function p.main(frame)
   local args=frame.args or {}
   local parent=frame.getParent(frame) or {}
   local pargs=parent.args or {}
   local textinput=args[1] or pargs[1] or ""
   local nowiki=args.nowiki or pargs.nowiki or nil
   local totalwidth=args.width or pargs.width or 220
   local totalheight=args.height or pargs.height or 200
   local debuglog=""
    --- Allow searching of all text to end with:
   textinput=textinput.."<Module:Block diagram internal end token>"
    --- Give all RECOGNIZED markup a consistent searchable string
    --- more styling should be added; seeking a first proof of concept now
   textinput=mw.ustring.gsub(textinput,"<left%s*(%-?%d*)%s*>","<Module:Block diagram internal left token:%1>")
   textinput=mw.ustring.gsub(textinput,"<top%s*(%-?%d*)%s*>","<Module:Block diagram internal top token:%1>")
   textinput=mw.ustring.gsub(textinput,"<right%s*(%-?%d*)%s*>","<Module:Block diagram internal right token:%1>")
   textinput=mw.ustring.gsub(textinput,"<bottom%s*(%-?%d*)%s*>","<Module:Block diagram internal bottom token:%1>")
   prowl=mw.ustring.gmatch(textinput,"(.-)<Module:Block diagram internal (%S+) token:([^>]*)>")
   local tableoutput={}
   local text,tag,value
   local default={}
   default['left']=0
   default['right']=100
   default['top']=0
   default['bottom']=100
   for i,j in pairs(default) do
      _G[i]=j
   end
   repeat
      text,tag,value = prowl(textinput)
      debuglog=debuglog..(text or "nil")..(tag or "nil")
      if not tag then return debuglog end
      table.insert(tableoutput,'<div style="position:absolute;top:')
      table.insert(tableoutput,top)
      table.insert(tableoutput,'%;bottom:')
      table.insert(tableoutput,bottom)
      table.insert(tableoutput,'%;left:')
      table.insert(tableoutput,left)
      table.insert(tableoutput,'%;right:')
      table.insert(tableoutput,right)
      table.insert(tableoutput,'%;border:1px solid black;">')
      table.insert(tableoutput,tag)
      table.insert(tableoutput,'</div>')
      _G[tag]=value or default[tag]
   until tag=="end"
   local textoutput=table.concat(tableoutput)
   textoutput='<div style="position:relative;width:'..totalwidth..'px;height:'..totalheight..'px;">{{vertical center|'..textoutput..'|text-align:center;}}</div>'
   if nowiki then textoutput=frame.preprocess("<pre><nowiki>"..textoutput.."</nowiki></pre>") end
   return textoutput
end

return p