difftreelog
feat add std.manifestToml
in: master
1 file changed
crates/jrsonnet-stdlib/src/std.jsonnetdiffbeforeafterboth830 ];830 ];831 std.join('\n', main_body + std.flattenArrays(all_sections) + ['']),831 std.join('\n', main_body + std.flattenArrays(all_sections) + ['']),832832833 manifestToml(value):: std.manifestTomlEx(value, ' '),834835 manifestTomlEx(value, indent)::836 local837 escapeStringToml = std.escapeStringJson,838 escapeKeyToml(key) =839 local bare_allowed = std.set(std.stringChars('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-'));840 if std.setUnion(std.set(std.stringChars(key)), bare_allowed) == bare_allowed then key else escapeStringToml(key),841 isTableArray(v) = std.isArray(v) && std.length(v) > 0 && std.foldl(function(a, b) a && std.isObject(b), v, true),842 isSection(v) = std.isObject(v) || isTableArray(v),843 renderValue(v, indexedPath, inline, cindent) =844 if v == true then845 'true'846 else if v == false then847 'false'848 else if v == null then849 error 'Tried to manifest "null" at ' + indexedPath850 else if std.isNumber(v) then851 '' + v852 else if std.isString(v) then853 escapeStringToml(v)854 else if std.isFunction(v) then855 error 'Tried to manifest function at ' + indexedPath856 else if std.isArray(v) then857 if std.length(v) == 0 then858 '[]'859 else860 local range = std.range(0, std.length(v) - 1);861 local new_indent = if inline then '' else cindent + indent;862 local separator = if inline then ' ' else '\n';863 local lines = ['[' + separator]864 + std.join([',' + separator],865 [866 [new_indent + renderValue(v[i], indexedPath + [i], true, '')]867 for i in range868 ])869 + [separator + (if inline then '' else cindent) + ']'];870 std.join('', lines)871 else if std.isObject(v) then872 local lines = ['{ ']873 + std.join([', '],874 [875 [escapeKeyToml(k) + ' = ' + renderValue(v[k], indexedPath + [k], true, '')]876 for k in std.objectFields(v)877 ])878 + [' }'];879 std.join('', lines),880 renderTableInternal(v, path, indexedPath, cindent) =881 local kvp = std.flattenArrays([882 [cindent + escapeKeyToml(k) + ' = ' + renderValue(v[k], indexedPath + [k], false, cindent)]883 for k in std.objectFields(v)884 if !isSection(v[k])885 ]);886 local sections = [std.join('\n', kvp)] + [887 (888 if std.isObject(v[k]) then889 renderTable(v[k], path + [k], indexedPath + [k], cindent)890 else891 renderTableArray(v[k], path + [k], indexedPath + [k], cindent)892 )893 for k in std.objectFields(v)894 if isSection(v[k])895 ];896 std.join('\n\n', sections),897 renderTable(v, path, indexedPath, cindent) =898 cindent + '[' + std.join('.', std.map(escapeKeyToml, path)) + ']'899 + (if v == {} then '' else '\n')900 + renderTableInternal(v, path, indexedPath, cindent + indent),901 renderTableArray(v, path, indexedPath, cindent) =902 local range = std.range(0, std.length(v) - 1);903 local sections = [904 (cindent + '[[' + std.join('.', std.map(escapeKeyToml, path)) + ']]'905 + (if v[i] == {} then '' else '\n')906 + renderTableInternal(v[i], path, indexedPath + [i], cindent + indent))907 for i in range908 ];909 std.join('\n\n', sections);910 if std.isObject(value) then911 renderTableInternal(value, [], [], '')912 else913 error 'TOML body must be an object. Got ' + std.type(value),914833 escapeStringJson(str_)::915 escapeStringJson(str_)::834 local str = std.toString(str_);916 local str = std.toString(str_);