Changes

582 bytes added ,  08:35, 29 March 2023
Update package: OSW Core
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 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
   
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 280: Line 290:  
end
 
end
 
end
 
end
wikitext = wikitext .. "<div class='jsonld-header' style='display:none' data-jsonld='" .. mw.text.jsonEncode( jsonld ) .. "'></div>"
+
wikitext = wikitext .. "<div class='jsonld-header' style='display:none' data-jsonld='" .. mw.text.jsonEncode( jsonld ):gsub("'","`") .. "'></div>"
 
end
 
end
 
 
Line 557: Line 567:  
local term_parts = p.splitString(term, "*")
 
local term_parts = p.splitString(term, "*")
 
if (string.find(term, "*", 0, true) and term_parts[1] == k) then --custom additional mapping term*(*...): "Property:..."
 
if (string.find(term, "*", 0, true) and term_parts[1] == k) then --custom additional mapping term*(*...): "Property:..."
table.insert(property_definitions, def)
+
if type(def) == 'table' then table.insert(property_definitions, def["@id"])
 +
else table.insert(property_definitions, def) end
 
end
 
end
 
end
 
end