55
edits
(Update package: OSW Core) |
(Update package: OSW Core) |
||
| (One intermediate revision by one other user not shown) | |||
| Line 163: | Line 163: | ||
local string_list = "" | local string_list = "" | ||
for i,e in pairs(v) do | for i,e in pairs(v) do | ||
local eval_template = nil | |||
local eval_templates = p.defaultArgPath(jsonschema, {"properties", k, "items", p.keys.template}, {}) | |||
if (eval_templates[1] == nil) then eval_templates = {eval_templates} end --ensure list of objects | |||
for i, t in pairs(eval_templates) do | |||
if (t[p.keys.mode] ~= nil and t[p.keys.mode] == mode) then eval_template = t --use only render templates in render mode and store templates in store mode | |||
elseif (t[p.keys.mode] == nil) then eval_template = t --default | |||
elseif (debug) then msg = msg .. "Ignore eval_template" .. mw.dumpObject( t ) .. "\n<br>" | |||
end | |||
end | |||
if type(e) == 'table' then | if type(e) == 'table' then | ||
local sub_res = p.expandEmbeddedTemplates({frame=frame, jsondata=e, jsonschema=p.defaultArgPath(jsonschema, {"properties", k, "items"}, {}), template=eval_template, mode=mode, stringify_arrays=stringify_arrays}) | local sub_res = p.expandEmbeddedTemplates({frame=frame, jsondata=e, jsonschema=p.defaultArgPath(jsonschema, {"properties", k, "items"}, {}), template=eval_template, mode=mode, stringify_arrays=stringify_arrays}) | ||
msg = msg .. sub_res.debug_msg | msg = msg .. sub_res.debug_msg | ||
| Line 182: | Line 185: | ||
end | end | ||
else | else | ||
if (eval_template ~= nil and eval_template["value"] ~= nil) then | |||
--evaluate single array item string as json {"self": "<value>", ".": "<value>"} | |||
local sub_res = p.expandEmbeddedTemplates({frame=frame, jsondata={["self"]=e,["."]=e}, jsonschema=p.defaultArgPath(jsonschema, {"properties", k, "items"}, {}), template=eval_template, mode=mode, stringify_arrays=stringify_arrays}) | |||
mw.logObject(sub_res) | |||
e = sub_res.res | |||
v[i] = e | |||
end | |||
if (stringify_arrays) then string_list = string_list .. e .. ";" end | if (stringify_arrays) then string_list = string_list .. e .. ";" end | ||
end | end | ||
| Line 288: | Line 298: | ||
--mw.log("JSONDATA RENDER") | --mw.log("JSONDATA RENDER") | ||
--mw.logObject(jsondata) | --mw.logObject(jsondata) | ||
local max_index = p.tableLength(schema_res.visited) | |||
for i, category in ipairs(schema_res.visited) do | for i, category in ipairs(schema_res.visited) do | ||
if (mode == p.mode.footer) then category = schema_res.visited[max_index - i +1] end --reverse order for footer templates | |||
local jsonschema = schema_res.jsonschemas[category] | local jsonschema = schema_res.jsonschemas[category] | ||
local template = schema_res.templates[category] | local template = schema_res.templates[category] | ||
| Line 309: | Line 320: | ||
--local display_label = "" | --local display_label = "" | ||
--if (jsondata[p.keys.label] ~= nil) then display_label = p.splitString(jsondata[p.keys.label], '@')[1] end | --if (jsondata[p.keys.label] ~= nil) then display_label = p.splitString(jsondata[p.keys.label], '@')[1] end | ||
if (title.nsText ~= "Category") then wikitext = wikitext .. "\n" .. p.setCategories({categories= | if (title.nsText ~= "Category") then wikitext = wikitext .. "\n" .. p.setCategories({categories=json_res_store.res[p.keys.category], sortkey=display_label}).wikitext end--items | ||
wikitext = wikitext .. p.setCategories({categories= | wikitext = wikitext .. p.setCategories({categories=json_res_store.res[p.keys.subcategory], sortkey=display_label}).wikitext --classes/categories | ||
if (smw_res ~= nil) then | if (smw_res ~= nil) then | ||
| Line 339: | Line 350: | ||
local schema = p.defaultArg(args.jsonschema, nil) | local schema = p.defaultArg(args.jsonschema, nil) | ||
local context = p.buildContext({jsonschema=schema}).context | local context = p.buildContext({jsonschema=schema}).context | ||
local ignore_properties = {[p.keys.category]=true} -- don't render type/category on every subclass | |||
local res = "" | local res = "" | ||
if schema == nil then return res end | if schema == nil then return res end | ||
| Line 354: | Line 366: | ||
:wikitext( schema_label ) | :wikitext( schema_label ) | ||
for k,v in pairs(jsondata) do | for k,v in pairs(jsondata) do | ||
if (schema['properties'] ~= nil and schema['properties'][k] ~= nil and (type(v) ~= 'table' or v[1] ~= nil)) then --literal or literal array | if (not ignore_properties[k]) then | ||
if (schema['properties'] ~= nil and schema['properties'][k] ~= nil and (type(v) ~= 'table' or v[1] ~= nil)) then --literal or literal array | |||
local def = schema['properties'][k] | |||
--mw.logObject(def) | |||
local label = k | |||
if def['title'] ~= nil then label = def['title'] end | |||
--res = res .. title ": " .. v | |||
local cell = tbl:tag( 'tr' ) | |||
:tag( 'th' ) | |||
:wikitext( label ) | |||
:done() | |||
:tag( 'td' ) | |||
if (type(v) == 'table') then | |||
for i,e in pairs(v) do | |||
if (type(e) ~= 'table') then | |||
local p_type = p.defaultArgPath(context, {k, '@type'}, '@value') | |||
if (p_type == '@id') then e = "[[" .. string.gsub(e, "Category:", ":Category:") .. "]]" end | |||
cell:wikitext("\n* " .. e .. "") | |||
end | |||
end | end | ||
else | |||
local p_type = p.defaultArgPath(context, {k, '@type'}, '@value') | |||
if (p_type == '@id') then v = "[[" .. string.gsub(v, "Category:", ":Category:") .. "]]" end | |||
cell:wikitext( v ) | |||
end | end | ||
end | end | ||
end | end | ||
edits