Module:Cbox

local p = {} local cbox local styles,css,args = {},{},{} local lomod = require('Dev:Cbox/layout') local chrome = require('Dev:Colors') local getArgs = require('Dev:Arguments').getArgs local function doublekey(str,v) local k,ka = 1,{} for n in mw.ustring.gmatch(str,'[^#]+') do       ka[k] = n        k=k+1 end if not styles[ka[2] or 'cbox'] then styles[ka[2] or 'cbox'] = {} end styles[ka[2] or 'cbox'][ka[1]] = v   args[str] = nil end local function multikey(loc,str,v) if type(str)=="table" then styles[loc]=styles[loc] or {} for i=1,#str do           styles[loc][str[i]] = v        end end end local function adddata(moto) args.text=args.text or '' if tostring(moto)=="table" then args.text=args.text..'entering is:table ' for k,v in pairs(moto) do           args.text=args.text..tostring(k)..':『'..tostring(v)..'』 ' end else args.text=args.text..'value:『'..tostring(moto)..'』 ' end end local function notmeta(k,v) if v=='' or v==nil then return false elseif mw.ustring.find(k,'#') then return true elseif k=='layout' or k=='header' or k=='text' or k=='reason' or   k=='reasontext' or k=='image' or k=='data' or k=='above' or    k=='below' or k=='quote' or k=='name' or k=='imagesize' or k=='class' or    k=='timestamp' or k=='towhere' or k=='fontsize' then return false end return true end local function autotext(size) if size then local o = size..'pt' local h = tostring(tonumber(size)+2)..'pt' styles['cbox'] = styles['cbox'] or {} styles['cbox']['font-size'] = o   styles['header'] = styles['header'] or {} styles['header']['font-size'] = h   end end local function colorfix(header) if styles[header] then local c,bc = styles[header]['color'],styles[header]['background-color'] if c and not bc then local ddc = {['args']={c}} styles[header]['background-color'] = chrome.text(ddc) elseif bc and not c then local ddc = {['args']={bc}} styles[header]['color']=chrome.text(ddc) end end end local function quickcreate(element,class) local cell = mw.html.create(element) cell:addClass(class) if styles[class] then cell:css(styles[class]) end if css[class] then cell:cssText(css[class]) end return cell end function p.maketest(frame) multikey('cbox',{"border-radius","-moz-border-radius","-webkit-border-radius","-khtml-border-radius","-icab-border-radius","-o-border-radius"},"30px") cbox=quickcreate('table','cbox') lomod.layout1 return tostring(cbox) end function p.test(frame) adddata(frame) local moto = getArgs(frame,{       valueFunc = function(key,value)            if not value then                return nil            end            local k = mw.ustring.lower(key)            if not(k=='header' or k=='text' or k=='reason' or k=='reasontext' or k=='image' or k=='data' or k=='above' or k=='below' or k=='quote' or k=='name' or k=='timestamp' or k=='towhere') then                value = mw.ustring.lower(value)            end            if mw.ustring.find(value,'%S') then                return value            end            return nil        end    }) for k,v in pairs(moto) do       key = mw.ustring.lower(k) if not args[key] then args[key] = v       end end adddata(args) if args.round and tonumber(args.round)>0 then multikey('cbox',{"border-radius","-moz-border-radius","-webkit-border-radius","-khtml-border-radius","-icab-border-radius","-o-border-radius"},args.round .. 'px') end css['cbox'] = args.style args.style = '' css['header'] = args.headerstyle args.headerstyle = '' css['description'] = args.textstyle args.textstyle = '' css['reason'] = args.reasonstyle args.reasonstyle = '' css['image'] = args.imagestyle args.imagestyle = '' autotext(args.fontsize) args.fontsize = '' -- Loop over all the args colorfix('cbox') colorfix('header') colorfix('reason') cbox = quickcreate('table','cbox') cbox:addClass(args['class'] or '') lomod.layout1 return tostring(cbox) end function p.main(frame) local moto = getArgs(frame,{       valueFunc = function(key,value)            if not value then                return nil            end            local k = mw.ustring.lower(key)            if not(k=='header' or k=='text' or k=='reason' or k=='reasontext' or k=='image' or k=='data' or k=='above' or k=='below' or k=='quote' or k=='name' or k=='timestamp' or k=='towhere') then                value = mw.ustring.lower(value)            end            if mw.ustring.find(value,'%S') then                return value            end            return nil        end    }) for k,v in pairs(moto) do       key = mw.ustring.lower(k) if not args[key] then args[key] = v       end end if args.round and tonumber(args.round)>0 then multikey('cbox',{"border-radius","-moz-border-radius","-webkit-border-radius","-khtml-border-radius","-icab-border-radius","-o-border-radius"},args.round .. 'px') end css['cbox'] = args.style args['style'] = '' css['header'] = args.headerstyle args.headerstyle = '' css['description'] = args.textstyle args.textstyle = '' css['reason'] = args.reasonstyle args.reasonstyle = '' css['image'] = args.imagestyle args.imagestyle = '' autotext(args.fontsize) args.fontsize = '' -- Loop over all the args for k,v in pairs(args) do       -- 先に↑を消すことで飛ばすようになる if notmeta(k,v) then doublekey(k,v) -- Simple copy end end colorfix('cbox') colorfix('header') colorfix('reason') cbox = quickcreate('table','cbox') cbox:addClass(args['class'] or '') local layout = tonumber(args.layout) if layout == 1 then cbox = lomod.layout1(cbox,styles,css,args) elseif layout == 2 then cbox = lomod.layout2(cbox,styles,css,args) elseif layout == 3 then cbox = lomod.layout3(cbox,styles,css,args) elseif layout == 4 then cbox = lomod.layout4(cbox,styles,css,args) elseif layout == 5 then cbox = lomod.layout5(cbox,styles,css,args) elseif layout == 6 then cbox = lomod.layout6(cbox,styles,css,args) end return tostring(cbox) end return p