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 19:06, 5 May 2013 (setting top/left - don't know if that matters, this is an html bug). 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:END>"
    --- 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
      debuglog=debuglog..i..j
   end
   repeat
      text,tag,value = prowl(textinput)
      debuglog=debuglog..(text or "nil")..(tag or "nil")
      if not tag then return debuglog end
      if (text or "")~="" then 
         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,text)
         table.insert(tableoutput,'</div>')
      end
      _G[tag]=value or default[tag]
   until tag=="end"
   local textoutput=table.concat(tableoutput)
   textoutput='<div style="position:relative;top:0;left:0;width:'..totalwidth..'px;height:'..totalheight..'px;">'..textoutput..'</div>'
   if nowiki then textoutput=frame:preprocess("<pre><nowiki>"..textoutput.."</nowiki></pre>") else textoutput=frame:preprocess(textoutput) end
   return textoutput,debuglog
end

return p