Module:Electowidget: Difference between revisions

This makes the get_data test work
(very crude start on Lua version of electowidget (and really, it's not much...))
 
(This makes the get_data test work)
 
(6 intermediate revisions by the same user not shown)
Line 1:
-- From: User:RobLa
-- 2019-12-09 - I might port electowidget to Lua. Maybe...
-- Date: ~~~~
-- Comment: I think I'd like the new version of Electowidget to use ABIF
local p = {}
 
function p.get_dataparse_prefs_line(line)
local qty, prefs = tostring(line):match('(%d+):%s*(.*)')
local prefs_table = {}
 
if prefs == '' then
return { qty = qty, comment = nil, orderedlist = true }
end
 
local rank = 1
 
--for name, rating in prefs:gmatch('([^/]+)/([^ ]+)') do
-- prefs_table[rank] = {
-- name = name,
-- rating = tonumber(rating),
-- }
prefs_table[0]={name="foo1" , rating=1}
prefs_table[1]={name="foo2" , rating=2}
 
qty = 9999
rank = rank + 1
-- end
 
return {
qty = tonumber(qty),
prefs = prefs_table,
comment = nil,
orderedlist = true
}
end
 
function p.prefs_line_json(prefsline)
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("2009 Burlington, Vermont Mayoral Election data"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