Difference between revisions of "Module:TNT"
Jump to navigation
Jump to search
implement p.doc
>Yurik |
>Yurik (implement p.doc) |
||
Line 48: | Line 48: | ||
return 'commons:' .. dataset | return 'commons:' .. dataset | ||
end | end | ||
end | |||
function p.doc( frame ) | |||
local dataset, id | |||
dataset = 'TemplateParams/Graph:Lines.tab' | |||
for k, v in pairs( frame.args ) do | |||
if k == 1 then | |||
dataset = v | |||
end | |||
end | |||
local data = mw.ext.data.get(dataset) | |||
local names = {} | |||
for _, field in pairs(data.schema.fields) do | |||
table.insert(names, field.name) | |||
end | |||
local params = {} | |||
local paramOrder = {} | |||
local index = 1 | |||
for _, row in pairs(data.data) do | |||
local newVal = {} | |||
local name = nil | |||
for pos, val in pairs(row) do | |||
local columnName = names[pos] | |||
if columnName == 'name' then | |||
name = val | |||
else | |||
newVal[columnName] = val | |||
end | |||
end | |||
if name then | |||
params[name] = newVal | |||
table.insert(paramOrder, index) | |||
index = index + 1 | |||
end | |||
end | |||
local templateData = { | |||
params=params, | |||
paramOrder=paramOrder, | |||
description=data.description | |||
} | |||
templateData = mw.text.jsonEncode(templateData) | |||
return frame:extensionTag('templatedata', templateData) | |||
end | end | ||
return p | return p |