词条 | Module:NPP/sandbox |
释义 | local p = {} function standardicon(modulename) index = {} -- Take modulename as input, returns corresponding icon filename -- Returns default icon if no icon is defined -- Grow the library! Add default icons as needed by adding this line below: -- index['MODULENAME'] = 'FILE NAME.ext' index['Discussions'] = 'Speechbubbles icon.svg' index['Tasks'] = 'ListBullet.svg' index['Watchlist'] = 'OpenEye icon.svg' index['Maps'] = 'MapPin.svg' index['Resources'] = 'Cite book.svg' index['Requests'] = 'Quotes icon.svg' index['Showcase'] = 'RibbonPrize.svg' index['Metrics'] = 'ArticleCheck.svg' index['Alerts'] = 'Bell icon.svg' index['Related WikiProjects'] = 'Contributions icon.svg'
for t, fn in pairs(index) do if t == modulename then return fn end end return 'Beta icon.svg' -- default if nothing matches end function p.build(frame) title = intro = image = color1 = '#6af' -- default value color2 = '#086' -- default value modules = {} for key, value in pairs(frame:getParent().args) do -- iterate through arguments, pick out values if key == 'title' then title = value elseif key == 'intro' then intro = value elseif key == 'image' then image = value elseif key == 'color1' then color1 = value elseif key == 'color2' then color2 = value elseif string.find(key, 'module') ~= nil then -- matches module1, module2, etc. id = string.gsub(key, 'module', '') id = tonumber(id) modules[id] = value end end -- Adding header header = "__NOTOC__\ " -- top container "header = header .. " " -- intro -- Adding project icon header = header .. " " "header = header .. image .. " -- Adding project title header = header .. " " -- header "-- Adding intro blurb header = header .. " " "header = header .. intro .. " -- Adding announcement section if mw.title.makeTitle('Wikipedia', title .. "/" .. "Announcements").exists == true then header = header .. frame:expandTemplate{ title = 'Wikipedia:' .. title .. "/" .. "Announcements", args = { color = color2 } } end header = header .. " -- Adding member box header = header .. " " "header = header .. frame:expandTemplate{ title = 'WPX member box', args = { color = color2 } } header = header .. " -- Closing off header header = header .. " -- Rendering table of contents and body toc_args = {width = 80, height = 55} -- passed into Image Array module toc_args['font-size'] = '100%' toc_args['margin'] = 0 body = ""
-- Load a Table of Contents entry, transclude module, for each named module counter = 0 for _, module in pairs(modules) do counter = counter + 1 toc_args['image' .. counter] = standardicon(module) toc_args['caption' .. counter] = "" .. module .. "" toc_args['alt' .. counter] = module toc_args['link' .. counter] = "#" .. module moduletitle = title .. "/" .. module if module == "Related WikiProjects" then -- Load the appropriate subpage of Related WikiProjects body = body .. "\" .. frame:expandTemplate{ title = "Wikipedia:Related WikiProjects/" .. title, args = {color1, color2} } else if mw.title.makeTitle('Wikipedia', moduletitle).exists == true then body = body .. "\" .. frame:expandTemplate{ title = 'Wikipedia:' .. moduletitle, args = {color1, color2} } .. "\ "else -- Create notice body = body .. "\" .. frame:expandTemplate{ title = 'WPX header', args = { module, color = color1 } } body = body .. "" .. moduletitle .. " does not exist." end end
end
toc_args['perrow'] = counter -- sets length of image array to the number of icons toc = " " .. frame:expandTemplate{ title='Image array', args = toc_args } .. " "-- Assembling parts contents = header .. toc .. body return contents end return p |
随便看 |
|
开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。