Content deleted Content added
remove that one |
from sandbox |
||
Line 3:
]]
require
local getArgs = require
local p = {}
Line 14:
local function class_percent(param, total)
-- These suck for i18n because the % is forced to the right without spacing,
-- both in a required context (CSS) and unrequired (to-be-displayed text).
-- I.e., there should be a separate version of this or a function parameter
-- which takes a boolean. :(
return tostring(round(100 * param / total)) .. '%'
end
local function percent_remaining(sum, total)
local remaining =
if remaining
return tostring(round(
else
return nil
Line 28 ⟶ 32:
local function category_count(category, project)
return mw.site.stats.pagesInCategory(
'pages'
)
-- 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)
return args[from_arg]
else▼
return default
end
Line 39 ⟶ 53:
function p._main(args, frame)
-- frame needs to be available for extensionTag and expandTemplate
local classes = {
Line 58 ⟶ 71:
}
local project = arg_or_default(args, "project", nil)
▲ if args['project'] and args['project'] ~= '' then
▲ else
▲ end
local sum_classes = 0
if project then
for
class
if class
class
project_classes[1]
project
)
end
sum_classes = sum_classes + class
end
else
-- 'or class.count' to keep us safe from a non-numeric value in args.
▲ for i, class in pairs(classes) do
▲ class['count'] = tonumber(args[i])
▲ sum_classes = sum_classes + class['count']
▲ end
end
end
Line 96 ⟶ 95:
local total
if project then
--
--
total = sum_classes + category_count(
project_classes[2]
project
)
else
total = tonumber(args[9]) or 100
end
Line 111 ⟶ 109:
:attr('role', 'presentation')
for
if class
local percentage = class_percent(class
root:newline() -- sprinkled through to make the HTML easier to read
-- 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
-- or maybe mw.html is just smarter than me.
:tag('td')
:css('background', frame:expandTemplate{
title = 'class/colour', args = { class
})
:css('width', percentage)
:tag('span')
-- wikitext accessibly-hidden by CSS
:wikitext(
:done()
:done()
Line 136 ⟶ 138:
:css('width', remaining)
:tag('span')
:wikitext(
:done()
:done()
:newline()
end
return frame:extensionTag{
name = 'templatestyles',
args = { src = 'Progression rainbow/styles.css'}
} .. '\n' .. tostring(root)
end
|