Module:Progression rainbow/sandbox: Difference between revisions

Content deleted Content added
last for the night
see if I break project
Line 30:
local function category_count(category, project)
return mw.site.stats.pagesInCategory(
-- specious use of string.format
string.format('%s %s articles', category, project),
'pages'
Line 38 ⟶ 37:
-- This is only done once in this module, here for demonstration.
-- Gist: Make it cleaner to initialize 'trivial' variables.
local function arg_or_default(args, from_arg, default)
if args[from_arg] and args[from_arg] ~= '' then
return args[from_arg]
Line 53 ⟶ 52:
function p._main(args, frame)
-- frame needs to be passed to p._main for extensionTag and expandTemplate
-- TODO: Digest what Johnuniq said on [[WT:Lua]] about the frame.
 
local classes = {
Line 70:
}
 
local project = arg_or_default(args, "project", nil)
local sum_classes = 0
Line 86:
else
-- Parameter 9 and others is the total non-project, so exclude
-- TODO: I can't get this to work cleanly with (i)pairs
for i = 1,8 do
-- 'or 0' to keep us safe from a non-numeric value.
Line 97:
if project then
-- It makes more sense to do this sum here rather than in the project
-- loop above, because total is initialized here in the non-project case
total = sum_classes + category_count(
project_classes[2].category,
Line 117:
-- I don't understand why we don't need to create a 'tr'. When
-- added deliberately, we get a <tr class='empty'></tr> hanging
-- out. Possibly a consequence of Remex instead of HTML Tidy
-- out.
-- or maybe mw.html is just smarter than me.
:tag('td')
:css('background', frame:expandTemplate{