Module:Electowidget: Difference between revisions

This makes the get_data test work
(added datapage param to p.get_data() rather than hardcoding to "2009 Burlington, Vermont Mayoral Election data")
(This makes the get_data test work)
 
(2 intermediate revisions by the same user not shown)
Line 3:
-- Comment: I think I'd like the new version of Electowidget to use ABIF
local p = {}
-- Function to parse the line and return a Lua native data structure
 
function p.parse_prefs_line(line)
if not line or line == '' then
return {}
end
 
local qty, prefs = tostring(line):match('(%d+):%s*(.*)')
local prefs_table = {}
Line 18 ⟶ 13:
 
local rank = 1
 
if 1 == 1 then
--for name, rating in prefs:gmatch('([^/]+)/([^ ]+)') do
return tostring(prefs)
-- prefs_table[rank] = {
end
-- name = name,
for name, rating in prefs:gmatch('([^/]+)/([^ ]+)') do
-- rating = tonumber(rating),
prefs_table[rank] = {
-- }
name = name,
prefs_table[0]={name="foo1" , rating = tonumber(rating),1}
prefs_table[1]={name="foo2" , rating=2}
}
 
qty = 9999
rank = rank + 1
-- end
 
return {
qty = tonumber(qty),
prefs = prefs_table or {},
comment = nil,
orderedlist = true
Line 37 ⟶ 34:
end
 
function p.get_dataprefs_line_json(datapageprefsline)
data = p.parse_prefs_line(prefsline)
return mw.text.jsonEncode(data)
end
 
 
function p.get_data(frame)
-- copied and adapted from
-- https://en.wikipedia.org/wiki/Module:Format_TemplateData
-- local title, s = mw.title.new(tostring(datapage))
local stitle = mw.title:getContent.new(frame.args[1])
local s = title:getContent()
local i, j = s:find( "<electowidget>", 1, true )
local r