Модуль:GetField: различия между версиями
Pok (обсуждение | вклад) Нет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| (не показаны 4 промежуточные версии этого же участника) | |||
| Строка 1093: | Строка 1093: | ||
if aPrimitive ~= bPrimitive then | if aPrimitive ~= bPrimitive then | ||
return aPrimitive | return not aPrimitive | ||
end | end | ||
| Строка 1100: | Строка 1100: | ||
return keys[1] | return keys[1] | ||
end | |||
local function is_wrapper_block_key(key) | |||
return type(key) == "string" and not key:match("^[%a_][%w_]*$") | |||
end | end | ||
| Строка 1121: | Строка 1125: | ||
end | end | ||
if options.skipPrimitiveRoot and is_array_of_primitives(value) then | if options.skipPrimitiveRoot and is_array_of_primitives(value) then | ||
return | return | ||
| Строка 1159: | Строка 1162: | ||
if next(v) ~= nil and not is_array_of_primitives(v) then | if next(v) ~= nil and not is_array_of_primitives(v) then | ||
local childPrefix = | local childPrefix | ||
if options.nestedKeyMode == "prefixed" then | |||
childPrefix = key | |||
elseif type(k) == "string" then | |||
childPrefix = key | |||
else | |||
childPrefix = nil | |||
end | |||
append_table_fields(parts, v, options, childPrefix) | append_table_fields(parts, v, options, childPrefix) | ||
end | end | ||
| Строка 1196: | Строка 1206: | ||
skipPrimitiveRoot = true, | skipPrimitiveRoot = true, | ||
} | } | ||
local function is_object_map(tbl) | |||
local count = 0 | |||
for k, v in pairs(tbl) do | |||
if type(k) ~= "string" or type(v) ~= "table" then | |||
return false | |||
end | |||
count = count + 1 | |||
end | |||
return count > 1 | |||
end | |||
local function makeCall(obj) | local function makeCall(obj) | ||
| Строка 1220: | Строка 1241: | ||
if k == idKey then | if k == idKey then | ||
if | if is_wrapper_block_key(k) then | ||
if type(v) == "table" then | if type(v) == "table" then | ||
local json = encode_nowiki_json(v) | |||
if json then | |||
parts[#parts + 1] = "value=" .. tostring(json) | |||
end | |||
append_table_fields(parts, v, rawTypeOptions, nil) | append_table_fields(parts, v, rawTypeOptions, nil) | ||
elseif v ~= nil then | elseif v ~= nil then | ||
| Строка 1240: | Строка 1265: | ||
elseif v ~= nil then | elseif v ~= nil then | ||
parts[#parts + 1] = "value=" .. tostring(v) | parts[#parts + 1] = "value=" .. tostring(v) | ||
parts[#parts + 1] = k .. "=" .. tostring(v) | |||
end | end | ||
else | else | ||
| Строка 1259: | Строка 1285: | ||
for _, item in ipairs(data) do | for _, item in ipairs(data) do | ||
makeCall(item) | makeCall(item) | ||
end | |||
elseif is_object_map(data) then | |||
local keys = collect_sorted_keys(data, true) | |||
for _, k in ipairs(keys) do | |||
makeCall({ [k] = data[k] }) | |||
end | end | ||
else | else | ||
| Строка 1283: | Строка 1314: | ||
end | end | ||
local outputType = (args.type or "list" | local outputType = (args.type or "list") | ||
local bullet = mw.text.unstripNoWiki(args.prefix or "* ") | local bullet = mw.text.unstripNoWiki(args.prefix or "* ") | ||
local sep = mw.text.unstripNoWiki(args.sep or ": ") | local sep = mw.text.unstripNoWiki(args.sep or ": ") | ||
if outputType == "none" then | if outputType == "none" then | ||
bullet = "" | bullet = "" | ||
sep = "" | sep = "" | ||
elseif outputType == "revertList" then | |||
sep = mw.text.unstripNoWiki(args.sep or " ") | |||
end | end | ||
| Строка 1380: | Строка 1414: | ||
if outputType == "enum" then | if outputType == "enum" then | ||
line = vStr .. " " .. keyStr | line = vStr .. " " .. keyStr | ||
elseif outputType == "revertList" then | |||
line = bullet .. vStr .. sep .. keyStr | |||
else | else | ||
line = bullet .. keyStr .. sep .. vStr | line = bullet .. keyStr .. sep .. vStr | ||
| Строка 1395: | Строка 1431: | ||
if outputType == "enum" then | if outputType == "enum" then | ||
return frame:preprocess(table.concat(out, ", ")) | return frame:preprocess(table.concat(out, ", ")) | ||
elseif outputType == "list" then | elseif outputType == "list" or outputType == "revertList" then | ||
return frame:preprocess(table.concat(out, "\n")) | return frame:preprocess(table.concat(out, "\n")) | ||
else | else | ||