Módulo:NPP
A documentação para este módulo pode ser criada em Módulo:NPP/doc
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['Participants'] = 'Contributions 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__\n<div style='display: flex; display: -webkit-flex; flex-flow: row wrap; -webkit-flex-flow: row wrap;'>" -- top container
header = header .. "<div style='flex: 1 0; -webkit-flex: 1 0; padding-bottom: 3em; border-top: solid .7em " .. color1 .. ";'>" -- intro
-- Adding project icon
header = header .. "<div class='nomobile' style='float:left; margin-top: 1em; margin-right: 2em; margin-bottom: 1em; text-align: center;'>"
header = header .. image .. "</div>"
-- Adding project title
header = header .. "<div style='font-size: 120%; padding: 0;'>" -- header
header = header .. "<h1 style='font-weight: bold; border-bottom: none; margin:0; padding-top:0.5em;'>" .. title .. "</h1></div>"
-- Adding intro blurb
header = header .. "<div style='margin-top: 1em; font-size: 110%;'>"
header = header .. intro .. "</div>"
-- 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 .. "</div>"
-- Closing off header
header = header .. "</div></div>"
-- 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 .. "|" .. module .. "]]"
toc_args['alt' .. counter] = module
toc_args['link' .. counter] = "#" .. module
moduletitle = title .. "/" .. module
if module == "Related WikiProjects" then
-- Load the appropriate subpage of [[Wikipedia:Related WikiProjects]]
body = body .. "\n" .. frame:expandTemplate{ title = "Wikipedia:Related WikiProjects/" .. title, args = {color1, color2} }
else
if mw.title.makeTitle('Wikipedia', moduletitle).exists == true then
body = body .. "\n" .. frame:expandTemplate{ title = 'Wikipedia:' .. moduletitle, args = {color1, color2} } .. "\n<div style='clear:both;'></div>"
else
-- Create notice
body = body .. "\n" .. frame:expandTemplate{ title = 'WPX header', args = { module, color = color1 } }
body = body .. "[[Wikipedia:" .. moduletitle .. "]] does not exist."
end
end
end
toc_args['perrow'] = counter -- sets length of image array to the number of icons
toc = "<div style='margin-bottom:4em;'>" .. frame:expandTemplate{ title='Image array', args = toc_args } .. "</div><div style='clear:both;'></div>"
-- Assembling parts
contents = header .. toc .. body
return contents
end
return p