mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 00:25:42 +02:00
helpers/lib: toLuaObject ignore empty attrs (#312)
This commit is contained in:
parent
3d64fab719
commit
35c56b62a1
2 changed files with 26 additions and 3 deletions
|
@ -12,6 +12,8 @@ with lib; rec {
|
|||
then
|
||||
if hasAttr "__raw" args
|
||||
then args.__raw
|
||||
else if hasAttr "__empty" args
|
||||
then "{ }"
|
||||
else
|
||||
"{"
|
||||
+ (concatStringsSep ","
|
||||
|
@ -20,7 +22,12 @@ with lib; rec {
|
|||
if head (stringToCharacters n) == "@"
|
||||
then toLuaObject v
|
||||
else "[${toLuaObject n}] = " + (toLuaObject v))
|
||||
(filterAttrs (n: v: !isNull v) args)))
|
||||
(filterAttrs
|
||||
(
|
||||
n: v:
|
||||
!isNull v && (toLuaObject v != "{}")
|
||||
)
|
||||
args)))
|
||||
+ "}"
|
||||
else if builtins.isList args
|
||||
then "{" + concatMapStringsSep "," toLuaObject args + "}"
|
||||
|
@ -40,6 +47,8 @@ with lib; rec {
|
|||
then "nil"
|
||||
else "";
|
||||
|
||||
emptyTable = {"__empty" = null;};
|
||||
|
||||
# Generates maps for a lua config
|
||||
genMaps = mode: maps: let
|
||||
normalized =
|
||||
|
|
|
@ -68,7 +68,7 @@
|
|||
expected = ''"foo\\bar\nbaz"'';
|
||||
};
|
||||
|
||||
testToLuaObjectShouldFilterNullAttrs = {
|
||||
testToLuaObjectFilters = {
|
||||
expr = helpers.toLuaObject {
|
||||
a = null;
|
||||
b = {};
|
||||
|
@ -78,7 +78,21 @@
|
|||
f = {};
|
||||
};
|
||||
};
|
||||
expected = ''{["b"] = {},["c"] = {},["d"] = {["f"] = {}}}'';
|
||||
expected = ''{}'';
|
||||
};
|
||||
|
||||
testToLuaObjectEmptyTable = {
|
||||
expr = helpers.toLuaObject {
|
||||
a = null;
|
||||
b = {};
|
||||
c = {__empty = null;};
|
||||
d = {
|
||||
e = null;
|
||||
f = {};
|
||||
g = helpers.emptyTable;
|
||||
};
|
||||
};
|
||||
expected = ''{["c"] = { },["d"] = {["g"] = { }}}'';
|
||||
};
|
||||
};
|
||||
in
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue