Content deleted Content added
let's see how completely broken this is |
use require('strict') instead of require('Module:No globals') |
||
(36 intermediate revisions by 3 users not shown) | |||
Line 3:
]]
require('
local getArgs = require('Module:Arguments').getArgs▼
local p = {}
Line 13 ⟶ 12:
end
local function
-- These suck for i18n because the % is forced to the right without spacing,
return string.format('%s %%', tostring(round(100 * param / total)))▼
-- both in a required context (CSS) and unrequired (to-be-displayed text).
-- I.e., there should be a separate version of this
end
local function percent_remaining(sum, total)
local remaining =
if remaining > 0 then
return
else
return nil
Line 33 ⟶ 35:
end
-- This is only done once in this module, here for demonstration.
-- Gist: Make it cleaner to initialize 'trivial' variables.
local function
if args[from_arg] and args[from_arg] ~= '' then
return args[from_arg]
Line 42 ⟶ 45:
end
function p.
end▼
function p._main(args, frame)▼
local classes = {
Line 66 ⟶ 63:
}
local project =
local sum_classes = 0
Line 81 ⟶ 78:
end
else
for
if arg ~= 9 then▼
▲ -- 'or 0' to keep us safe from a non-numeric value. Can consider
▲ classes[arg].count = tonumber(value) or 0
▲ sum_classes = sum_classes + class.count
end▼
end
end
Line 95 ⟶ 88:
if project then
-- It makes more sense to do this sum here rather than in the project
-- loop above
total = sum_classes + category_count(
project_classes[2].category,
Line 104 ⟶ 97:
end
local
local root = mw.html.create('ul')
root:addClass('progression-rainbow')
root:css('height', height)
local current_frame = mw.getCurrentFrame()
for _, class in
if class.count ~= 0 then
local percentage =
root:newline() -- sprinkled through to make the HTML easier to read
root:tag('
:css('background',
title = 'class/colour', args = { class.class
})
:css('width', percentage)
:attr('title', string.format('%s %s', percentage, class.category))
:tag('span')
:addClass('sr-only')
:wikitext(string.format('%s %s', percentage, class.category)) :done()
:done()
end
end
Line 128 ⟶ 127:
local remaining = percent_remaining(sum_classes, total)
if remaining then
root:tag('
:addClass('remaining')
:css('width', remaining)
:tag('span')
▲ :wikitext(string.format('%s remaining', remaining))
:
:wikitext(string.format('%s remaining', remaining))
:done()▼
:done()
▲ :done()
:newline()
end
root:allDone()
return
name = 'templatestyles', args = { src = 'Module:Progression rainbow/styles.css'}
} .. current_frame:extensionTag{
name = 'templatestyles', args = { src = 'Screen reader-only/styles.css'}
} .. '\n' .. tostring(root)
▲end
end
|